@@ -32,6 +32,8 @@ const {
3232 ObjectCreate,
3333 ObjectKeys,
3434 String,
35+ StringPrototypeCharCodeAt,
36+ StringPrototypeSlice,
3537} = primordials ;
3638
3739const { Buffer } = require ( 'buffer' ) ;
@@ -86,20 +88,20 @@ function unescapeBuffer(s, decodeSpaces) {
8688 // Flag to know if some hex chars have been decoded
8789 let hasHex = false ;
8890 while ( index < s . length ) {
89- currentChar = s . charCodeAt ( index ) ;
91+ currentChar = StringPrototypeCharCodeAt ( s , index ) ;
9092 if ( currentChar === 43 /* '+' */ && decodeSpaces ) {
9193 out [ outIndex ++ ] = 32 ; // ' '
9294 index ++ ;
9395 continue ;
9496 }
9597 if ( currentChar === 37 /* '%' */ && index < maxLength ) {
96- currentChar = s . charCodeAt ( ++ index ) ;
98+ currentChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
9799 hexHigh = unhexTable [ currentChar ] ;
98100 if ( ! ( hexHigh >= 0 ) ) {
99101 out [ outIndex ++ ] = 37 ; // '%'
100102 continue ;
101103 } else {
102- nextChar = s . charCodeAt ( ++ index ) ;
104+ nextChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
103105 hexLow = unhexTable [ nextChar ] ;
104106 if ( ! ( hexLow >= 0 ) ) {
105107 out [ outIndex ++ ] = 37 ; // '%'
@@ -231,10 +233,10 @@ function stringify(obj, sep, eq, options) {
231233
232234function charCodes ( str ) {
233235 if ( str . length === 0 ) return [ ] ;
234- if ( str . length === 1 ) return [ str . charCodeAt ( 0 ) ] ;
236+ if ( str . length === 1 ) return [ StringPrototypeCharCodeAt ( str , 0 ) ] ;
235237 const ret = new Array ( str . length ) ;
236238 for ( let i = 0 ; i < str . length ; ++ i )
237- ret [ i ] = str . charCodeAt ( i ) ;
239+ ret [ i ] = StringPrototypeCharCodeAt ( str , i ) ;
238240 return ret ;
239241}
240242const defSepCodes = [ 38 ] ; // &
@@ -268,8 +270,8 @@ function parse(qs, sep, eq, options) {
268270 return obj ;
269271 }
270272
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 ) ) ) ;
273275 const sepLen = sepCodes . length ;
274276 const eqLen = eqCodes . length ;
275277
@@ -300,7 +302,7 @@ function parse(qs, sep, eq, options) {
300302 const plusChar = ( customDecode ? '%20' : ' ' ) ;
301303 let encodeCheck = 0 ;
302304 for ( let i = 0 ; i < qs . length ; ++ i ) {
303- const code = qs . charCodeAt ( i ) ;
305+ const code = StringPrototypeCharCodeAt ( qs , i ) ;
304306
305307 // Try matching key/value pair separator (e.g. '&')
306308 if ( code === sepCodes [ sepIdx ] ) {
@@ -311,7 +313,7 @@ function parse(qs, sep, eq, options) {
311313 // We didn't find the (entire) key/value separator
312314 if ( lastPos < end ) {
313315 // Treat the substring as part of the key instead of the value
314- key += qs . slice ( lastPos , end ) ;
316+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
315317 } else if ( key . length === 0 ) {
316318 // We saw an empty substring between separators
317319 if ( -- pairs === 0 )
@@ -321,7 +323,7 @@ function parse(qs, sep, eq, options) {
321323 continue ;
322324 }
323325 } else if ( lastPos < end ) {
324- value += qs . slice ( lastPos , end ) ;
326+ value += StringPrototypeSlice ( qs , lastPos , end ) ;
325327 }
326328
327329 addKeyVal ( obj , key , value , keyEncoded , valEncoded , decode ) ;
@@ -343,7 +345,7 @@ function parse(qs, sep, eq, options) {
343345 // Key/value separator match!
344346 const end = i - eqIdx + 1 ;
345347 if ( lastPos < end )
346- key += qs . slice ( lastPos , end ) ;
348+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
347349 encodeCheck = 0 ;
348350 lastPos = i + 1 ;
349351 }
@@ -369,15 +371,15 @@ function parse(qs, sep, eq, options) {
369371 }
370372 if ( code === 43 /* + */ ) {
371373 if ( lastPos < i )
372- key += qs . slice ( lastPos , i ) ;
374+ key += StringPrototypeSlice ( qs , lastPos , i ) ;
373375 key += plusChar ;
374376 lastPos = i + 1 ;
375377 continue ;
376378 }
377379 }
378380 if ( code === 43 /* + */ ) {
379381 if ( lastPos < i )
380- value += qs . slice ( lastPos , i ) ;
382+ value += StringPrototypeSlice ( qs , lastPos , i ) ;
381383 value += plusChar ;
382384 lastPos = i + 1 ;
383385 } else if ( ! valEncoded ) {
@@ -400,9 +402,9 @@ function parse(qs, sep, eq, options) {
400402 // Deal with any leftover key or value data
401403 if ( lastPos < qs . length ) {
402404 if ( eqIdx < eqLen )
403- key += qs . slice ( lastPos ) ;
405+ key += StringPrototypeSlice ( qs , lastPos ) ;
404406 else if ( sepIdx < sepLen )
405- value += qs . slice ( lastPos ) ;
407+ value += StringPrototypeSlice ( qs , lastPos ) ;
406408 } else if ( eqIdx === 0 && key . length === 0 ) {
407409 // We ended on an empty substring
408410 return obj ;
0 commit comments