Skip to content

Commit f16e8c8

Browse files
Fix: invalid regex used in cutAfterJS (#1137)
* support regex in `utils#cutAfterJSON` * fix test and code * add support for single and backtick quoted strings to cutAfterJSON * yet another unit-test * update comments * fix regex & add another test
1 parent a299081 commit f16e8c8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ESCAPING_SEQUENZES = [
6060
{ start: "'", end: "'" },
6161
{ start: '`', end: '`' },
6262
// RegeEx
63-
{ start: '/', end: '/', startPrefix: /(^|[[{:;,])\s+$/ },
63+
{ start: '/', end: '/', startPrefix: /(^|[[{:;,])\s?$/ },
6464
];
6565

6666
/**

test/utils-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ describe('utils.cutAfterJS()', () => {
6464
'{"a": "\\"}1", "b": 1, "c": /[0-9]}}\\/}/}',
6565
);
6666
});
67+
it('Tolerant to string with regexes in arrays ', () => {
68+
assert.strictEqual(
69+
// This does also tests "startPrefix" of the RegEx-Escaping-Sequenze
70+
// I already screwed up the preceding whitespace rule once...
71+
utils.cutAfterJS('{"a": [-1929233002,b,/,][}",],()}(\\[)/,2070160835,1561177444]}abcd'),
72+
'{"a": [-1929233002,b,/,][}",],()}(\\[)/,2070160835,1561177444]}',
73+
);
74+
});
6775
it('does not fail for division followed by a regex', () => {
6876
assert.strictEqual(
69-
utils.cutAfterJS('{"a": "\\"}1", "b": 1, "c": [4/6, /[0-9]}}\\/}/]}abcd', true),
77+
utils.cutAfterJS('{"a": "\\"}1", "b": 1, "c": [4/6, /[0-9]}}\\/}/]}abcd'),
7078
'{"a": "\\"}1", "b": 1, "c": [4/6, /[0-9]}}\\/}/]}',
7179
);
7280
});

0 commit comments

Comments
 (0)