Skip to content

Commit

Permalink
2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
okuryu committed Dec 4, 2019
1 parent 16a68ab commit 433fc9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module.exports = function serialize(obj, options) {
}

if (type === 'R') {
return "new RegExp(\"" + regexps[valueIndex].source + "\", \"" + regexps[valueIndex].flags + "\")";
return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
}

if (type === 'M') {
Expand Down
10 changes: 5 additions & 5 deletions test/unit/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,22 @@ describe('serialize( obj )', function () {
});

it('should serialize regexps with escaped chars', function () {
expect(serialize(/\..*/)).to.equal('new RegExp("\\..*", "")');
expect(serialize(new RegExp('\\..*'))).to.equal('new RegExp("\\..*", "")');
expect(serialize(/\..*/)).to.equal('new RegExp("\\\\..*", "")');
expect(serialize(new RegExp('\\..*'))).to.equal('new RegExp("\\\\..*", "")');
});

it('should deserialize regexps with escaped chars', function () {
var re = eval(serialize(/\..*/));
expect(re).to.be.a('RegExp');
expect(re.source).to.equal('..*');
expect(re.source).to.equal('\\..*');
re = eval(serialize(new RegExp('\\..*')));
expect(re).to.be.a('RegExp');
expect(re.source).to.equal('..*');
expect(re.source).to.equal('\\..*');
});

it('should serialize dangerous regexps', function () {
var re = /[</script><script>alert('xss')//]/
expect(serialize(re)).to.be.a('string').equal('new RegExp("[<\\/script><script>alert(\'xss\')\\/\\/]", "")');
expect(serialize(re)).to.be.a('string').equal('new RegExp("[\\u003C\\\\\\u002Fscript\\u003E\\u003Cscript\\u003Ealert(\'xss\')\\\\\\u002F\\\\\\u002F]", "")');
});
});

Expand Down

0 comments on commit 433fc9c

Please sign in to comment.