File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,28 @@ function stringPercentDecode (input) {
188
188
return percentDecode ( bytes )
189
189
}
190
190
191
+ /**
192
+ * @param {number } byte
193
+ */
191
194
function isHexCharByte ( byte ) {
192
195
// 0-9 A-F a-f
193
196
return ( byte >= 0x30 && byte <= 0x39 ) || ( byte >= 0x41 && byte <= 0x46 ) || ( byte >= 0x61 && byte <= 0x66 )
194
197
}
195
198
199
+ /**
200
+ * @param {number } byte
201
+ */
202
+ function hexByteToNumber ( byte ) {
203
+ return (
204
+ // 0-9
205
+ byte >= 0x30 && byte <= 0x39
206
+ ? ( byte - 48 )
207
+ // Convert to uppercase
208
+ // ((byte & 0xDF) - 65) + 10
209
+ : ( ( byte & 0xDF ) - 55 )
210
+ )
211
+ }
212
+
196
213
// https://url.spec.whatwg.org/#percent-decode
197
214
/** @param {Uint8Array } input */
198
215
function percentDecode ( input ) {
@@ -224,11 +241,8 @@ function percentDecode (input) {
224
241
} else {
225
242
// 1. Let bytePoint be the two bytes after byte in input,
226
243
// decoded, and then interpreted as hexadecimal number.
227
- const nextTwoBytes = String . fromCharCode ( input [ i + 1 ] , input [ i + 2 ] )
228
- const bytePoint = Number . parseInt ( nextTwoBytes , 16 )
229
-
230
244
// 2. Append a byte whose value is bytePoint to output.
231
- output [ j ++ ] = bytePoint
245
+ output [ j ++ ] = ( hexByteToNumber ( input [ i + 1 ] ) << 4 ) | hexByteToNumber ( input [ i + 2 ] )
232
246
233
247
// 3. Skip the next two bytes in input.
234
248
i += 2
You can’t perform that action at this time.
0 commit comments