@@ -32,6 +32,8 @@ const {
3232 ObjectCreate,
3333 ObjectKeys,
3434 String,
35+ StringPrototypeCharCodeAt,
36+ StringPrototypeSlice,
3537} = primordials ;
3638
3739const { Buffer } = require ( 'buffer' ) ;
@@ -91,20 +93,20 @@ function unescapeBuffer(s, decodeSpaces) {
9193 // Flag to know if some hex chars have been decoded
9294 let hasHex = false ;
9395 while ( index < s . length ) {
94- currentChar = s . charCodeAt ( index ) ;
96+ currentChar = StringPrototypeCharCodeAt ( s , index ) ;
9597 if ( currentChar === 43 /* '+' */ && decodeSpaces ) {
9698 out [ outIndex ++ ] = 32 ; // ' '
9799 index ++ ;
98100 continue ;
99101 }
100102 if ( currentChar === 37 /* '%' */ && index < maxLength ) {
101- currentChar = s . charCodeAt ( ++ index ) ;
103+ currentChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
102104 hexHigh = unhexTable [ currentChar ] ;
103105 if ( ! ( hexHigh >= 0 ) ) {
104106 out [ outIndex ++ ] = 37 ; // '%'
105107 continue ;
106108 } else {
107- nextChar = s . charCodeAt ( ++ index ) ;
109+ nextChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
108110 hexLow = unhexTable [ nextChar ] ;
109111 if ( ! ( hexLow >= 0 ) ) {
110112 out [ outIndex ++ ] = 37 ; // '%'
@@ -272,10 +274,10 @@ function stringify(obj, sep, eq, options) {
272274 */
273275function charCodes ( str ) {
274276 if ( str . length === 0 ) return [ ] ;
275- if ( str . length === 1 ) return [ str . charCodeAt ( 0 ) ] ;
277+ if ( str . length === 1 ) return [ StringPrototypeCharCodeAt ( str , 0 ) ] ;
276278 const ret = new Array ( str . length ) ;
277279 for ( let i = 0 ; i < str . length ; ++ i )
278- ret [ i ] = str . charCodeAt ( i ) ;
280+ ret [ i ] = StringPrototypeCharCodeAt ( str , i ) ;
279281 return ret ;
280282}
281283const defSepCodes = [ 38 ] ; // &
@@ -319,8 +321,8 @@ function parse(qs, sep, eq, options) {
319321 return obj ;
320322 }
321323
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 ) ) ) ;
324326 const sepLen = sepCodes . length ;
325327 const eqLen = eqCodes . length ;
326328
@@ -351,7 +353,7 @@ function parse(qs, sep, eq, options) {
351353 const plusChar = ( customDecode ? '%20' : ' ' ) ;
352354 let encodeCheck = 0 ;
353355 for ( let i = 0 ; i < qs . length ; ++ i ) {
354- const code = qs . charCodeAt ( i ) ;
356+ const code = StringPrototypeCharCodeAt ( qs , i ) ;
355357
356358 // Try matching key/value pair separator (e.g. '&')
357359 if ( code === sepCodes [ sepIdx ] ) {
@@ -362,7 +364,7 @@ function parse(qs, sep, eq, options) {
362364 // We didn't find the (entire) key/value separator
363365 if ( lastPos < end ) {
364366 // Treat the substring as part of the key instead of the value
365- key += qs . slice ( lastPos , end ) ;
367+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
366368 } else if ( key . length === 0 ) {
367369 // We saw an empty substring between separators
368370 if ( -- pairs === 0 )
@@ -372,7 +374,7 @@ function parse(qs, sep, eq, options) {
372374 continue ;
373375 }
374376 } else if ( lastPos < end ) {
375- value += qs . slice ( lastPos , end ) ;
377+ value += StringPrototypeSlice ( qs , lastPos , end ) ;
376378 }
377379
378380 addKeyVal ( obj , key , value , keyEncoded , valEncoded , decode ) ;
@@ -394,7 +396,7 @@ function parse(qs, sep, eq, options) {
394396 // Key/value separator match!
395397 const end = i - eqIdx + 1 ;
396398 if ( lastPos < end )
397- key += qs . slice ( lastPos , end ) ;
399+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
398400 encodeCheck = 0 ;
399401 lastPos = i + 1 ;
400402 }
@@ -420,15 +422,15 @@ function parse(qs, sep, eq, options) {
420422 }
421423 if ( code === 43 /* + */ ) {
422424 if ( lastPos < i )
423- key += qs . slice ( lastPos , i ) ;
425+ key += StringPrototypeSlice ( qs , lastPos , i ) ;
424426 key += plusChar ;
425427 lastPos = i + 1 ;
426428 continue ;
427429 }
428430 }
429431 if ( code === 43 /* + */ ) {
430432 if ( lastPos < i )
431- value += qs . slice ( lastPos , i ) ;
433+ value += StringPrototypeSlice ( qs , lastPos , i ) ;
432434 value += plusChar ;
433435 lastPos = i + 1 ;
434436 } else if ( ! valEncoded ) {
@@ -451,9 +453,9 @@ function parse(qs, sep, eq, options) {
451453 // Deal with any leftover key or value data
452454 if ( lastPos < qs . length ) {
453455 if ( eqIdx < eqLen )
454- key += qs . slice ( lastPos ) ;
456+ key += StringPrototypeSlice ( qs , lastPos ) ;
455457 else if ( sepIdx < sepLen )
456- value += qs . slice ( lastPos ) ;
458+ value += StringPrototypeSlice ( qs , lastPos ) ;
457459 } else if ( eqIdx === 0 && key . length === 0 ) {
458460 // We ended on an empty substring
459461 return obj ;
0 commit comments