From 433fc9cafe375b3f376efd12730b226035c3ee3a Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Thu, 5 Dec 2019 07:15:39 +0900 Subject: [PATCH] 2.1.1 --- index.js | 2 +- test/unit/serialize.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 47c7701..3594167 100644 --- a/index.js +++ b/index.js @@ -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') { diff --git a/test/unit/serialize.js b/test/unit/serialize.js index 07ce236..5241916 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -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 = /[