@@ -251,7 +251,7 @@ describe('serialize( obj )', function () {
251
251
describe ( 'regexps' , function ( ) {
252
252
it ( 'should serialize constructed regexps' , function ( ) {
253
253
var re = new RegExp ( 'asdf' ) ;
254
- expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( '/ asdf/ ' ) ;
254
+ expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( 'new RegExp(" asdf", "") ' ) ;
255
255
} ) ;
256
256
257
257
it ( 'should deserialize constructed regexps' , function ( ) {
@@ -262,7 +262,7 @@ describe('serialize( obj )', function () {
262
262
263
263
it ( 'should serialize literal regexps' , function ( ) {
264
264
var re = / a s d f / ;
265
- expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( '/ asdf/ ' ) ;
265
+ expect ( serialize ( re ) ) . to . be . a ( 'string' ) . equal ( 'new RegExp(" asdf", "") ' ) ;
266
266
} ) ;
267
267
268
268
it ( 'should deserialize literal regexps' , function ( ) {
@@ -273,7 +273,7 @@ describe('serialize( obj )', function () {
273
273
274
274
it ( 'should serialize regexps with flags' , function ( ) {
275
275
var re = / ^ a s d f $ / gi;
276
- expect ( serialize ( re ) ) . to . equal ( '/ ^asdf$/gi ' ) ;
276
+ expect ( serialize ( re ) ) . to . equal ( 'new RegExp(" ^asdf$", "gi") ' ) ;
277
277
} ) ;
278
278
279
279
it ( 'should deserialize regexps with flags' , function ( ) {
@@ -285,17 +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 ( '/ \\..*/ ' ) ;
289
- expect ( serialize ( new RegExp ( '\\..*' ) ) ) . to . equal ( '/ \\..*/ ' ) ;
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
+ } ) ;
300
+
301
+ it ( 'should serialize dangerous regexps' , function ( ) {
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\')\\/\\/]", "")' ) ;
299
304
} ) ;
300
305
} ) ;
301
306
@@ -332,8 +337,8 @@ describe('serialize( obj )', function () {
332
337
[ 'a' , 123 ] ,
333
338
[ regexKey , 456 ]
334
339
] ) ;
335
- expect ( serialize ( m ) ) . to . be . a ( 'string' ) . equal ( 'new Map([["a",123],[/.*/ ,456]])' ) ;
336
- expect ( serialize ( { t : [ m ] } ) ) . to . be . a ( 'string' ) . equal ( '{"t":[new Map([["a",123],[/.*/ ,456]])]}' ) ;
340
+ expect ( serialize ( m ) ) . to . be . a ( 'string' ) . equal ( 'new Map([["a",123],[new RegExp(".*", "") ,456]])' ) ;
341
+ expect ( serialize ( { t : [ m ] } ) ) . to . be . a ( 'string' ) . equal ( '{"t":[new Map([["a",123],[new RegExp(".*", "") ,456]])]}' ) ;
337
342
} ) ;
338
343
339
344
it ( 'should deserialize a map' , function ( ) {
@@ -354,8 +359,8 @@ describe('serialize( obj )', function () {
354
359
123 ,
355
360
regex
356
361
] ) ;
357
- expect ( serialize ( m ) ) . to . be . a ( 'string' ) . equal ( 'new Set(["a",123,/.*/ ])' ) ;
358
- expect ( serialize ( { t : [ m ] } ) ) . to . be . a ( 'string' ) . equal ( '{"t":[new Set(["a",123,/.*/ ])]}' ) ;
362
+ expect ( serialize ( m ) ) . to . be . a ( 'string' ) . equal ( 'new Set(["a",123,new RegExp(".*", "") ])' ) ;
363
+ expect ( serialize ( { t : [ m ] } ) ) . to . be . a ( 'string' ) . equal ( '{"t":[new Set(["a",123,new RegExp(".*", "") ])]}' ) ;
359
364
} ) ;
360
365
361
366
it ( 'should deserialize a set' , function ( ) {
0 commit comments