@@ -7,6 +7,20 @@ import {
77const OPAQUE_KEY_MAX_LENGTH = 2048
88const UNSAFE_OPAQUE_KEY = / [ \\ / ? # \u0000 - \u001f \u007f ] /
99
10+ function hasWellFormedUtf16 ( value : string ) : boolean {
11+ for ( let index = 0 ; index < value . length ; index ++ ) {
12+ const codeUnit = value . charCodeAt ( index )
13+ if ( codeUnit >= 0xd800 && codeUnit <= 0xdbff ) {
14+ const next = value . charCodeAt ( index + 1 )
15+ if ( ! ( next >= 0xdc00 && next <= 0xdfff ) ) return false
16+ index ++
17+ } else if ( codeUnit >= 0xdc00 && codeUnit <= 0xdfff ) {
18+ return false
19+ }
20+ }
21+ return true
22+ }
23+
1024export interface OracleFusionCollection < T > {
1125 items : T [ ]
1226 count : number
@@ -111,7 +125,9 @@ function getOnlySelfLink(value: unknown): URL {
111125 throw new Error ( 'Oracle response must include exactly one self link' )
112126 }
113127 const href = ( selfLinks [ 0 ] as Record < string , unknown > ) . href
114- if ( typeof href !== 'string' ) throw new Error ( 'Oracle self link is malformed' )
128+ if ( typeof href !== 'string' || ! hasWellFormedUtf16 ( href ) ) {
129+ throw new Error ( 'Oracle self link is malformed' )
130+ }
115131 try {
116132 return new URL ( href )
117133 } catch {
@@ -157,17 +173,8 @@ function validateOpaqueKey(key: string): string {
157173 ) {
158174 throw new Error ( 'Oracle resource key is not a safe opaque path segment' )
159175 }
160- for ( let index = 0 ; index < key . length ; index ++ ) {
161- const codeUnit = key . charCodeAt ( index )
162- if ( codeUnit >= 0xd800 && codeUnit <= 0xdbff ) {
163- const next = key . charCodeAt ( index + 1 )
164- if ( ! ( next >= 0xdc00 && next <= 0xdfff ) ) {
165- throw new Error ( 'Oracle resource key contains malformed Unicode' )
166- }
167- index ++
168- } else if ( codeUnit >= 0xdc00 && codeUnit <= 0xdfff ) {
169- throw new Error ( 'Oracle resource key contains malformed Unicode' )
170- }
176+ if ( ! hasWellFormedUtf16 ( key ) ) {
177+ throw new Error ( 'Oracle resource key contains malformed Unicode' )
171178 }
172179 return key
173180}
0 commit comments