@@ -32,6 +32,8 @@ const {
32
32
ObjectCreate,
33
33
ObjectKeys,
34
34
String,
35
+ StringPrototypeCharCodeAt,
36
+ StringPrototypeSlice,
35
37
} = primordials ;
36
38
37
39
const { Buffer } = require ( 'buffer' ) ;
@@ -86,20 +88,20 @@ function unescapeBuffer(s, decodeSpaces) {
86
88
// Flag to know if some hex chars have been decoded
87
89
let hasHex = false ;
88
90
while ( index < s . length ) {
89
- currentChar = s . charCodeAt ( index ) ;
91
+ currentChar = StringPrototypeCharCodeAt ( s , index ) ;
90
92
if ( currentChar === 43 /* '+' */ && decodeSpaces ) {
91
93
out [ outIndex ++ ] = 32 ; // ' '
92
94
index ++ ;
93
95
continue ;
94
96
}
95
97
if ( currentChar === 37 /* '%' */ && index < maxLength ) {
96
- currentChar = s . charCodeAt ( ++ index ) ;
98
+ currentChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
97
99
hexHigh = unhexTable [ currentChar ] ;
98
100
if ( ! ( hexHigh >= 0 ) ) {
99
101
out [ outIndex ++ ] = 37 ; // '%'
100
102
continue ;
101
103
} else {
102
- nextChar = s . charCodeAt ( ++ index ) ;
104
+ nextChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
103
105
hexLow = unhexTable [ nextChar ] ;
104
106
if ( ! ( hexLow >= 0 ) ) {
105
107
out [ outIndex ++ ] = 37 ; // '%'
@@ -231,10 +233,10 @@ function stringify(obj, sep, eq, options) {
231
233
232
234
function charCodes ( str ) {
233
235
if ( str . length === 0 ) return [ ] ;
234
- if ( str . length === 1 ) return [ str . charCodeAt ( 0 ) ] ;
236
+ if ( str . length === 1 ) return [ StringPrototypeCharCodeAt ( str , 0 ) ] ;
235
237
const ret = new Array ( str . length ) ;
236
238
for ( let i = 0 ; i < str . length ; ++ i )
237
- ret [ i ] = str . charCodeAt ( i ) ;
239
+ ret [ i ] = StringPrototypeCharCodeAt ( str , i ) ;
238
240
return ret ;
239
241
}
240
242
const defSepCodes = [ 38 ] ; // &
@@ -268,8 +270,8 @@ function parse(qs, sep, eq, options) {
268
270
return obj ;
269
271
}
270
272
271
- const sepCodes = ( ! sep ? defSepCodes : charCodes ( sep + '' ) ) ;
272
- const eqCodes = ( ! eq ? defEqCodes : charCodes ( eq + '' ) ) ;
273
+ const sepCodes = ( ! sep ? defSepCodes : charCodes ( String ( sep ) ) ) ;
274
+ const eqCodes = ( ! eq ? defEqCodes : charCodes ( String ( eq ) ) ) ;
273
275
const sepLen = sepCodes . length ;
274
276
const eqLen = eqCodes . length ;
275
277
@@ -300,7 +302,7 @@ function parse(qs, sep, eq, options) {
300
302
const plusChar = ( customDecode ? '%20' : ' ' ) ;
301
303
let encodeCheck = 0 ;
302
304
for ( let i = 0 ; i < qs . length ; ++ i ) {
303
- const code = qs . charCodeAt ( i ) ;
305
+ const code = StringPrototypeCharCodeAt ( qs , i ) ;
304
306
305
307
// Try matching key/value pair separator (e.g. '&')
306
308
if ( code === sepCodes [ sepIdx ] ) {
@@ -311,7 +313,7 @@ function parse(qs, sep, eq, options) {
311
313
// We didn't find the (entire) key/value separator
312
314
if ( lastPos < end ) {
313
315
// Treat the substring as part of the key instead of the value
314
- key += qs . slice ( lastPos , end ) ;
316
+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
315
317
} else if ( key . length === 0 ) {
316
318
// We saw an empty substring between separators
317
319
if ( -- pairs === 0 )
@@ -321,7 +323,7 @@ function parse(qs, sep, eq, options) {
321
323
continue ;
322
324
}
323
325
} else if ( lastPos < end ) {
324
- value += qs . slice ( lastPos , end ) ;
326
+ value += StringPrototypeSlice ( qs , lastPos , end ) ;
325
327
}
326
328
327
329
addKeyVal ( obj , key , value , keyEncoded , valEncoded , decode ) ;
@@ -343,7 +345,7 @@ function parse(qs, sep, eq, options) {
343
345
// Key/value separator match!
344
346
const end = i - eqIdx + 1 ;
345
347
if ( lastPos < end )
346
- key += qs . slice ( lastPos , end ) ;
348
+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
347
349
encodeCheck = 0 ;
348
350
lastPos = i + 1 ;
349
351
}
@@ -369,15 +371,15 @@ function parse(qs, sep, eq, options) {
369
371
}
370
372
if ( code === 43 /* + */ ) {
371
373
if ( lastPos < i )
372
- key += qs . slice ( lastPos , i ) ;
374
+ key += StringPrototypeSlice ( qs , lastPos , i ) ;
373
375
key += plusChar ;
374
376
lastPos = i + 1 ;
375
377
continue ;
376
378
}
377
379
}
378
380
if ( code === 43 /* + */ ) {
379
381
if ( lastPos < i )
380
- value += qs . slice ( lastPos , i ) ;
382
+ value += StringPrototypeSlice ( qs , lastPos , i ) ;
381
383
value += plusChar ;
382
384
lastPos = i + 1 ;
383
385
} else if ( ! valEncoded ) {
@@ -400,9 +402,9 @@ function parse(qs, sep, eq, options) {
400
402
// Deal with any leftover key or value data
401
403
if ( lastPos < qs . length ) {
402
404
if ( eqIdx < eqLen )
403
- key += qs . slice ( lastPos ) ;
405
+ key += StringPrototypeSlice ( qs , lastPos ) ;
404
406
else if ( sepIdx < sepLen )
405
- value += qs . slice ( lastPos ) ;
407
+ value += StringPrototypeSlice ( qs , lastPos ) ;
406
408
} else if ( eqIdx === 0 && key . length === 0 ) {
407
409
// We ended on an empty substring
408
410
return obj ;
0 commit comments