Puppet highlighter: Fix over-greedy regexp detection #978
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
regex
token was allowing /regexps/ to start after the wordnode
or afterany non-word character. This ends up being too greedy! For example, take this
common code, using variable interpolation in a string that represents a file
path:
The highlighter will start a regexp at
/.ssh
, in the middle of the string, andcontinue for however many lines it takes to reach another slash.
So instead, let's be more conservative about where we might find a regexp. I
suggest:
node
.~=([{,
=~
/!~
operators,function calls, case statement and selector blocks, arrays, and data type
objects that accept parameters (
Pattern[/.../]
, etc.).=>
(and the lesser-used+>
) for hashes and resource attributes.in
operator. (I'm not 100%sure we should cover this case for a simple highlighter like Prism, and it's
the one I'd most expect to cause problems later, but... I think it's ok...)
This commit appears to fix the worst of the mid-string blowouts.