@@ -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' ) ;
@@ -91,20 +93,20 @@ function unescapeBuffer(s, decodeSpaces) {
91
93
// Flag to know if some hex chars have been decoded
92
94
let hasHex = false ;
93
95
while ( index < s . length ) {
94
- currentChar = s . charCodeAt ( index ) ;
96
+ currentChar = StringPrototypeCharCodeAt ( s , index ) ;
95
97
if ( currentChar === 43 /* '+' */ && decodeSpaces ) {
96
98
out [ outIndex ++ ] = 32 ; // ' '
97
99
index ++ ;
98
100
continue ;
99
101
}
100
102
if ( currentChar === 37 /* '%' */ && index < maxLength ) {
101
- currentChar = s . charCodeAt ( ++ index ) ;
103
+ currentChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
102
104
hexHigh = unhexTable [ currentChar ] ;
103
105
if ( ! ( hexHigh >= 0 ) ) {
104
106
out [ outIndex ++ ] = 37 ; // '%'
105
107
continue ;
106
108
} else {
107
- nextChar = s . charCodeAt ( ++ index ) ;
109
+ nextChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
108
110
hexLow = unhexTable [ nextChar ] ;
109
111
if ( ! ( hexLow >= 0 ) ) {
110
112
out [ outIndex ++ ] = 37 ; // '%'
@@ -272,10 +274,10 @@ function stringify(obj, sep, eq, options) {
272
274
*/
273
275
function charCodes ( str ) {
274
276
if ( str . length === 0 ) return [ ] ;
275
- if ( str . length === 1 ) return [ str . charCodeAt ( 0 ) ] ;
277
+ if ( str . length === 1 ) return [ StringPrototypeCharCodeAt ( str , 0 ) ] ;
276
278
const ret = new Array ( str . length ) ;
277
279
for ( let i = 0 ; i < str . length ; ++ i )
278
- ret [ i ] = str . charCodeAt ( i ) ;
280
+ ret [ i ] = StringPrototypeCharCodeAt ( str , i ) ;
279
281
return ret ;
280
282
}
281
283
const defSepCodes = [ 38 ] ; // &
@@ -319,8 +321,8 @@ function parse(qs, sep, eq, options) {
319
321
return obj ;
320
322
}
321
323
322
- const sepCodes = ( ! sep ? defSepCodes : charCodes ( sep + '' ) ) ;
323
- const eqCodes = ( ! eq ? defEqCodes : charCodes ( eq + '' ) ) ;
324
+ const sepCodes = ( ! sep ? defSepCodes : charCodes ( String ( sep ) ) ) ;
325
+ const eqCodes = ( ! eq ? defEqCodes : charCodes ( String ( eq ) ) ) ;
324
326
const sepLen = sepCodes . length ;
325
327
const eqLen = eqCodes . length ;
326
328
@@ -351,7 +353,7 @@ function parse(qs, sep, eq, options) {
351
353
const plusChar = ( customDecode ? '%20' : ' ' ) ;
352
354
let encodeCheck = 0 ;
353
355
for ( let i = 0 ; i < qs . length ; ++ i ) {
354
- const code = qs . charCodeAt ( i ) ;
356
+ const code = StringPrototypeCharCodeAt ( qs , i ) ;
355
357
356
358
// Try matching key/value pair separator (e.g. '&')
357
359
if ( code === sepCodes [ sepIdx ] ) {
@@ -362,7 +364,7 @@ function parse(qs, sep, eq, options) {
362
364
// We didn't find the (entire) key/value separator
363
365
if ( lastPos < end ) {
364
366
// Treat the substring as part of the key instead of the value
365
- key += qs . slice ( lastPos , end ) ;
367
+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
366
368
} else if ( key . length === 0 ) {
367
369
// We saw an empty substring between separators
368
370
if ( -- pairs === 0 )
@@ -372,7 +374,7 @@ function parse(qs, sep, eq, options) {
372
374
continue ;
373
375
}
374
376
} else if ( lastPos < end ) {
375
- value += qs . slice ( lastPos , end ) ;
377
+ value += StringPrototypeSlice ( qs , lastPos , end ) ;
376
378
}
377
379
378
380
addKeyVal ( obj , key , value , keyEncoded , valEncoded , decode ) ;
@@ -394,7 +396,7 @@ function parse(qs, sep, eq, options) {
394
396
// Key/value separator match!
395
397
const end = i - eqIdx + 1 ;
396
398
if ( lastPos < end )
397
- key += qs . slice ( lastPos , end ) ;
399
+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
398
400
encodeCheck = 0 ;
399
401
lastPos = i + 1 ;
400
402
}
@@ -420,15 +422,15 @@ function parse(qs, sep, eq, options) {
420
422
}
421
423
if ( code === 43 /* + */ ) {
422
424
if ( lastPos < i )
423
- key += qs . slice ( lastPos , i ) ;
425
+ key += StringPrototypeSlice ( qs , lastPos , i ) ;
424
426
key += plusChar ;
425
427
lastPos = i + 1 ;
426
428
continue ;
427
429
}
428
430
}
429
431
if ( code === 43 /* + */ ) {
430
432
if ( lastPos < i )
431
- value += qs . slice ( lastPos , i ) ;
433
+ value += StringPrototypeSlice ( qs , lastPos , i ) ;
432
434
value += plusChar ;
433
435
lastPos = i + 1 ;
434
436
} else if ( ! valEncoded ) {
@@ -451,9 +453,9 @@ function parse(qs, sep, eq, options) {
451
453
// Deal with any leftover key or value data
452
454
if ( lastPos < qs . length ) {
453
455
if ( eqIdx < eqLen )
454
- key += qs . slice ( lastPos ) ;
456
+ key += StringPrototypeSlice ( qs , lastPos ) ;
455
457
else if ( sepIdx < sepLen )
456
- value += qs . slice ( lastPos ) ;
458
+ value += StringPrototypeSlice ( qs , lastPos ) ;
457
459
} else if ( eqIdx === 0 && key . length === 0 ) {
458
460
// We ended on an empty substring
459
461
return obj ;
0 commit comments