@@ -805,7 +805,7 @@ const noEscape = [
805
805
const paramHexTable = hexTable . slice ( ) ;
806
806
paramHexTable [ 0x20 ] = '+' ;
807
807
808
- function escapeParam ( str ) {
808
+ function encodeStr ( str , noEscapeTable , hexTable ) {
809
809
const len = str . length ;
810
810
if ( len === 0 )
811
811
return '' ;
@@ -818,12 +818,12 @@ function escapeParam(str) {
818
818
819
819
// ASCII
820
820
if ( c < 0x80 ) {
821
- if ( noEscape [ c ] === 1 )
821
+ if ( noEscapeTable [ c ] === 1 )
822
822
continue ;
823
823
if ( lastPos < i )
824
824
out += str . slice ( lastPos , i ) ;
825
825
lastPos = i + 1 ;
826
- out += paramHexTable [ c ] ;
826
+ out += hexTable [ c ] ;
827
827
continue ;
828
828
}
829
829
@@ -833,15 +833,15 @@ function escapeParam(str) {
833
833
// Multi-byte characters ...
834
834
if ( c < 0x800 ) {
835
835
lastPos = i + 1 ;
836
- out += paramHexTable [ 0xC0 | ( c >> 6 ) ] +
837
- paramHexTable [ 0x80 | ( c & 0x3F ) ] ;
836
+ out += hexTable [ 0xC0 | ( c >> 6 ) ] +
837
+ hexTable [ 0x80 | ( c & 0x3F ) ] ;
838
838
continue ;
839
839
}
840
840
if ( c < 0xD800 || c >= 0xE000 ) {
841
841
lastPos = i + 1 ;
842
- out += paramHexTable [ 0xE0 | ( c >> 12 ) ] +
843
- paramHexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] +
844
- paramHexTable [ 0x80 | ( c & 0x3F ) ] ;
842
+ out += hexTable [ 0xE0 | ( c >> 12 ) ] +
843
+ hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] +
844
+ hexTable [ 0x80 | ( c & 0x3F ) ] ;
845
845
continue ;
846
846
}
847
847
// Surrogate pair
@@ -857,10 +857,10 @@ function escapeParam(str) {
857
857
}
858
858
lastPos = i + 1 ;
859
859
c = 0x10000 + ( ( ( c & 0x3FF ) << 10 ) | c2 ) ;
860
- out += paramHexTable [ 0xF0 | ( c >> 18 ) ] +
861
- paramHexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ] +
862
- paramHexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] +
863
- paramHexTable [ 0x80 | ( c & 0x3F ) ] ;
860
+ out += hexTable [ 0xF0 | ( c >> 18 ) ] +
861
+ hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ] +
862
+ hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] +
863
+ hexTable [ 0x80 | ( c & 0x3F ) ] ;
864
864
}
865
865
if ( lastPos === 0 )
866
866
return str ;
@@ -876,9 +876,17 @@ function serializeParams(array) {
876
876
if ( len === 0 )
877
877
return '' ;
878
878
879
- var output = `${ escapeParam ( array [ 0 ] ) } =${ escapeParam ( array [ 1 ] ) } ` ;
880
- for ( var i = 2 ; i < len ; i += 2 )
881
- output += `&${ escapeParam ( array [ i ] ) } =${ escapeParam ( array [ i + 1 ] ) } ` ;
879
+ const firstEncodedParam = encodeStr ( array [ 0 ] , noEscape , paramHexTable ) ;
880
+ const firstEncodedValue = encodeStr ( array [ 1 ] , noEscape , paramHexTable ) ;
881
+ let output =
882
+ `${ firstEncodedParam } =${ firstEncodedValue } ` ;
883
+
884
+ for ( var i = 2 ; i < len ; i += 2 ) {
885
+ const encodedParam = encodeStr ( array [ i ] , noEscape , paramHexTable ) ;
886
+ const encodedValue = encodeStr ( array [ i + 1 ] , noEscape , paramHexTable ) ;
887
+ output += `&${ encodedParam } =${ encodedValue } ` ;
888
+ }
889
+
882
890
return output ;
883
891
}
884
892
@@ -1422,5 +1430,6 @@ module.exports = {
1422
1430
domainToUnicode,
1423
1431
urlToOptions,
1424
1432
formatSymbol : kFormat ,
1425
- searchParamsSymbol : searchParams
1433
+ searchParamsSymbol : searchParams ,
1434
+ encodeStr
1426
1435
} ;
0 commit comments