File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ // more stringent version of encodeURIComponent
4
+ // (from https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
5
+ function fixedEncodeURIComponent ( str ) {
6
+ return encodeURIComponent ( str ) . replace ( / [ ! ' ( ) * ] / g, function ( c ) {
7
+ return '%' + c . charCodeAt ( 0 ) . toString ( 16 ) ;
8
+ } ) ;
9
+ }
10
+
3
11
exports . extract = function ( maybeUrl ) {
4
12
return maybeUrl . split ( '?' ) [ 1 ] || '' ;
5
13
} ;
@@ -43,10 +51,10 @@ exports.stringify = function (obj) {
43
51
44
52
if ( Array . isArray ( val ) ) {
45
53
return val . sort ( ) . map ( function ( val2 ) {
46
- return encodeURIComponent ( key ) + '=' + encodeURIComponent ( val2 ) ;
54
+ return fixedEncodeURIComponent ( key ) + '=' + fixedEncodeURIComponent ( val2 ) ;
47
55
} ) . join ( '&' ) ;
48
56
}
49
57
50
- return encodeURIComponent ( key ) + '=' + encodeURIComponent ( val ) ;
58
+ return fixedEncodeURIComponent ( key ) + '=' + fixedEncodeURIComponent ( val ) ;
51
59
} ) . join ( '&' ) : '' ;
52
60
} ;
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ describe('.stringify()', function () {
62
62
63
63
it ( 'URI encode' , function ( ) {
64
64
assert . strictEqual ( qs . stringify ( { 'foo bar' : 'baz faz' } ) , 'foo%20bar=baz%20faz' ) ;
65
+ assert . strictEqual ( qs . stringify ( { 'foo bar' : "baz'faz" } ) , 'foo%20bar=baz%27faz' ) ;
65
66
} ) ;
66
67
67
68
it ( 'handle array value' , function ( ) {
@@ -88,4 +89,4 @@ describe('.extract()', function () {
88
89
qs . extract ( undefined ) ;
89
90
} , TypeError ) ;
90
91
} ) ;
91
- } ) ;
92
+ } ) ;
You can’t perform that action at this time.
0 commit comments