File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,12 @@ QueryString.escape = function(str) {
138
138
}
139
139
// Surrogate pair
140
140
++ i ;
141
- c = 0x10000 + ( ( ( c & 0x3FF ) << 10 ) | ( str . charCodeAt ( i ) & 0x3FF ) ) ;
141
+ var c2 ;
142
+ if ( i < str . length )
143
+ c2 = str . charCodeAt ( i ) & 0x3FF ;
144
+ else
145
+ throw new URIError ( 'URI malformed' ) ;
146
+ c = 0x10000 + ( ( ( c & 0x3FF ) << 10 ) | c2 ) ;
142
147
out += hexTable [ 0xF0 | ( c >> 18 ) ] +
143
148
hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ] +
144
149
hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] +
Original file line number Diff line number Diff line change @@ -139,6 +139,11 @@ qsWeirdObjects.forEach(function(testCase) {
139
139
assert . equal ( testCase [ 1 ] , qs . stringify ( testCase [ 0 ] ) ) ;
140
140
} ) ;
141
141
142
+ // invalid surrogate pair throws URIError
143
+ assert . throws ( function ( ) {
144
+ qs . stringify ( { foo : '\udc00' } ) ;
145
+ } , URIError ) ;
146
+
142
147
// coerce numbers to string
143
148
assert . strictEqual ( 'foo=0' , qs . stringify ( { foo : 0 } ) ) ;
144
149
assert . strictEqual ( 'foo=0' , qs . stringify ( { foo : - 0 } ) ) ;
You can’t perform that action at this time.
0 commit comments