@@ -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
8789let hasHex = false ;
8890while ( index < s . length ) {
89- currentChar = s . charCodeAt ( index ) ;
91+ currentChar = StringPrototypeCharCodeAt ( s , index ) ;
9092if ( currentChar === 43 /* '+' */ && decodeSpaces ) {
9193out [ outIndex ++ ] = 32 ; // ' '
9294index ++ ;
9395continue ;
9496}
9597if ( currentChar === 37 /* '%' */ && index < maxLength ) {
96- currentChar = s . charCodeAt ( ++ index ) ;
98+ currentChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
9799hexHigh = unhexTable [ currentChar ] ;
98100if ( ! ( hexHigh >= 0 ) ) {
99101out [ outIndex ++ ] = 37 ; // '%'
100102continue ;
101103} else {
102- nextChar = s . charCodeAt ( ++ index ) ;
104+ nextChar = StringPrototypeCharCodeAt ( s , ++ index ) ;
103105hexLow = unhexTable [ nextChar ] ;
104106if ( ! ( hexLow >= 0 ) ) {
105107out [ outIndex ++ ] = 37 ; // '%'
@@ -231,10 +233,10 @@ function stringify(obj, sep, eq, options) {
231233
232234function charCodes ( str ) {
233235if ( str . length === 0 ) return [ ] ;
234- if ( str . length === 1 ) return [ str . charCodeAt ( 0 ) ] ;
236+ if ( str . length === 1 ) return [ StringPrototypeCharCodeAt ( str , 0 ) ] ;
235237const ret = new Array ( str . length ) ;
236238for ( let i = 0 ; i < str . length ; ++ i )
237- ret [ i ] = str . charCodeAt ( i ) ;
239+ ret [ i ] = StringPrototypeCharCodeAt ( str , i ) ;
238240return ret ;
239241}
240242const defSepCodes = [ 38 ] ; // &
@@ -268,8 +270,8 @@ function parse(qs, sep, eq, options) {
268270return 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 ) ) ) ;
273275const sepLen = sepCodes . length ;
274276const eqLen = eqCodes . length ;
275277
@@ -300,7 +302,7 @@ function parse(qs, sep, eq, options) {
300302const plusChar = ( customDecode ? '%20' : ' ' ) ;
301303let encodeCheck = 0 ;
302304for ( 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. '&')
306308if ( code === sepCodes [ sepIdx ] ) {
@@ -311,7 +313,7 @@ function parse(qs, sep, eq, options) {
311313// We didn't find the (entire) key/value separator
312314if ( 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
317319if ( -- pairs === 0 )
@@ -321,7 +323,7 @@ function parse(qs, sep, eq, options) {
321323continue ;
322324}
323325} else if ( lastPos < end ) {
324- value += qs . slice ( lastPos , end ) ;
326+ value += StringPrototypeSlice ( qs , lastPos , end ) ;
325327}
326328
327329addKeyVal ( obj , key , value , keyEncoded , valEncoded , decode ) ;
@@ -343,7 +345,7 @@ function parse(qs, sep, eq, options) {
343345// Key/value separator match!
344346const end = i - eqIdx + 1 ;
345347if ( lastPos < end )
346- key += qs . slice ( lastPos , end ) ;
348+ key += StringPrototypeSlice ( qs , lastPos , end ) ;
347349encodeCheck = 0 ;
348350lastPos = i + 1 ;
349351}
@@ -369,15 +371,15 @@ function parse(qs, sep, eq, options) {
369371}
370372if ( code === 43 /* + */ ) {
371373if ( lastPos < i )
372- key += qs . slice ( lastPos , i ) ;
374+ key += StringPrototypeSlice ( qs , lastPos , i ) ;
373375key += plusChar ;
374376lastPos = i + 1 ;
375377continue ;
376378}
377379}
378380if ( code === 43 /* + */ ) {
379381if ( lastPos < i )
380- value += qs . slice ( lastPos , i ) ;
382+ value += StringPrototypeSlice ( qs , lastPos , i ) ;
381383value += plusChar ;
382384lastPos = 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
401403if ( lastPos < qs . length ) {
402404if ( eqIdx < eqLen )
403- key += qs . slice ( lastPos ) ;
405+ key += StringPrototypeSlice ( qs , lastPos ) ;
404406else 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
408410return obj ;
0 commit comments