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) {
188188 }
189189
190190 if ( type === 'R' ) {
191- return "new RegExp(\"" + regexps [ valueIndex ] . source + "\ ", \"" + regexps [ valueIndex ] . flags + "\")" ;
191+ return "new RegExp(" + serialize ( regexps [ valueIndex ] . source ) + ", \"" + regexps [ valueIndex ] . flags + "\")" ;
192192 }
193193
194194 if ( type === 'M' ) {
Original file line number Diff line number Diff line change @@ -285,22 +285,22 @@ describe('serialize( obj )', function () {
285285 } ) ;
286286
287287 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("\\\\ ..*", "")' ) ;
290290 } ) ;
291291
292292 it ( 'should deserialize regexps with escaped chars' , function ( ) {
293293 var re = eval ( serialize ( / \. .* / ) ) ;
294294 expect ( re ) . to . be . a ( 'RegExp' ) ;
295- expect ( re . source ) . to . equal ( '..*' ) ;
295+ expect ( re . source ) . to . equal ( '\\ ..*' ) ;
296296 re = eval ( serialize ( new RegExp ( '\\..*' ) ) ) ;
297297 expect ( re ) . to . be . a ( 'RegExp' ) ;
298- expect ( re . source ) . to . equal ( '..*' ) ;
298+ expect ( re . source ) . to . equal ( '\\ ..*' ) ;
299299 } ) ;
300300
301301 it ( 'should serialize dangerous regexps' , function ( ) {
302302 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 ]", "")' ) ;
304304 } ) ;
305305 } ) ;
306306
You can’t perform that action at this time.
0 commit comments