File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ module.exports = function serialize(obj, options) {
188
188
}
189
189
190
190
if ( type === 'R' ) {
191
- return "new RegExp(\"" + regexps [ valueIndex ] . source + "\ ", \"" + regexps [ valueIndex ] . flags + "\")" ;
191
+ return "new RegExp(" + serialize ( regexps [ valueIndex ] . source ) + ", \"" + regexps [ valueIndex ] . flags + "\")" ;
192
192
}
193
193
194
194
if ( type === 'M' ) {
Original file line number Diff line number Diff line change @@ -285,22 +285,22 @@ describe('serialize( obj )', function () {
285
285
} ) ;
286
286
287
287
it ( 'should serialize regexps with escaped chars' , function ( ) {
288
- expect ( serialize ( / \. .* / ) ) . to . equal ( 'new RegExp("\\..*", "")' ) ;
289
- expect ( serialize ( new RegExp ( '\\..*' ) ) ) . to . equal ( 'new RegExp("\\..*", "")' ) ;
288
+ expect ( serialize ( / \. .* / ) ) . to . equal ( 'new RegExp("\\\\ ..*", "")' ) ;
289
+ expect ( serialize ( new RegExp ( '\\..*' ) ) ) . to . equal ( 'new RegExp("\\\\ ..*", "")' ) ;
290
290
} ) ;
291
291
292
292
it ( 'should deserialize regexps with escaped chars' , function ( ) {
293
293
var re = eval ( serialize ( / \. .* / ) ) ;
294
294
expect ( re ) . to . be . a ( 'RegExp' ) ;
295
- expect ( re . source ) . to . equal ( '..*' ) ;
295
+ expect ( re . source ) . to . equal ( '\\ ..*' ) ;
296
296
re = eval ( serialize ( new RegExp ( '\\..*' ) ) ) ;
297
297
expect ( re ) . to . be . a ( 'RegExp' ) ;
298
- expect ( re . source ) . to . equal ( '..*' ) ;
298
+ expect ( re . source ) . to . equal ( '\\ ..*' ) ;
299
299
} ) ;
300
300
301
301
it ( 'should serialize dangerous regexps' , function ( ) {
302
302
var re = / [ < / s c r i p t > < s c r i p t > a l e r t ( ' x s s ' ) / / ] /
303
- expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( 'new RegExp("[<\\/script><script>alert (\'xss\')\\/\\/ ]", "")' ) ;
303
+ expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( 'new RegExp("[\\u003C\\\\\\u002Fscript\\u003E\\u003Cscript\\u003Ealert (\'xss\')\\\\\\u002F\\\\\\u002F ]", "")' ) ;
304
304
} ) ;
305
305
} ) ;
306
306
You can’t perform that action at this time.
0 commit comments