Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 6086114

Browse files
WliuWliu
authored andcommitted
Fix catastrophic backtracking?
1 parent 65b20ed commit 6086114

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

grammars/jsdoc.cson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@
276276
\\s*
277277
(
278278
# The inner regexes are to stop the match early at */ and to not stop at escaped quotes
279-
(?:
279+
(?>
280280
"(?:(?:\\*(?!/))|(?:\\\\(?!"))|[^*\\\\])*?" | # [foo="bar"] Double-quoted
281281
'(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?' | # [foo='bar'] Single-quoted
282282
\\[ (?:(?:\\*(?!/))|[^*])*? \\] | # [foo=[1,2]] Array literal
283-
(?:(?:\\*(?!/))|[^*])*? # Everything else
283+
(?:(?:\\*(?!/))|\\s(?!\\s*\\])|\\[.*?(?:\\]|(?=\\*/))|[^*\\s\\[\\]])* # Everything else (sorry)
284284
)*
285285
)
286286
)?

spec/jsdoc-spec.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,3 +1527,9 @@ describe "JSDoc grammar", ->
15271527
expect(tokens[27]).toEqual value: '*/', scopes: ['source.js', 'comment.block.documentation.js', 'punctuation.definition.comment.end.js']
15281528
expect(tokens[29]).toEqual value: '20', scopes: ['source.js', 'constant.numeric.decimal.js']
15291529
expect(tokens[30]).toEqual value: ';', scopes: ['source.js', 'punctuation.terminator.statement.js']
1530+
1531+
describe "when the line ends without a closing bracket", ->
1532+
it "does not attempt to match the optional value (regression)", ->
1533+
{tokens} = grammar.tokenizeLine('/** @param {array} [bar = "x" REMOVE THE CLOSE BRACKET HERE.')
1534+
expect(tokens[9]).toEqual value: '[', scopes: ['source.js', 'comment.block.documentation.js']
1535+
expect(tokens[11]).toEqual value: ' = "x" REMOVE THE CLOSE BRACKET HERE.', scopes: ['source.js', 'comment.block.documentation.js']

0 commit comments

Comments
 (0)