Skip to content

Commit 181d7d5

Browse files
committed
1 parent 39f6ddf commit 181d7d5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function serialize (source, opts) {
7575
out += !/^\s*(function|\([^)]*\)\s*=>)/m.test(tmp) ? 'function ' + tmp : tmp
7676
} else if (util.isObject(source)) {
7777
if (util.isRegExp(source)) {
78-
out += source.toString()
78+
out += 'new RegExp("' + source.source + '", "' + source.flags + '")'
7979
} else if (util.isDate(source)) {
8080
out += 'new Date("' + source.toJSON() + '")'
8181
} else if (util.isError(source)) {

test/fixtures.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
],
3434
'regex': [
3535
/test(?:it)?/ig,
36-
'/test(?:it)?/gi'
36+
'new RegExp("test(?:it)?", "gi")'
3737
],
3838
'object': [
3939
{ a: 1, b: 2 },
@@ -138,6 +138,14 @@ module.exports = {
138138
new Float64Array([1e12, 2000000, 3.1415, -4.9e2, 5]),
139139
'new Float64Array([1000000000000, 2000000, 3.1415, -490, 5])',
140140
'toString'
141+
],
142+
'regexXss': [
143+
/[</script><script>alert('xss')//]/i,
144+
'new RegExp("[</script><script>alert(\'xss\')//]", "i")'
145+
],
146+
'regex no flags': [
147+
/abc/,
148+
'new RegExp("abc", "")'
141149
]
142150
}
143151

0 commit comments

Comments
 (0)