-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Null access for empty matches with greedy matching #3052
Copy link
Copy link
Closed
Description
So I just found this bug. If a greedy token creates an empty match m at the end of the string (m = re.exec(text); m[0] == "" && m.index == text.length), then matchGrammar will throw a TypeError. This line throws the error.
What happens is that the greedy matching algorithm tries to find the string or token with the index of m. Since there cannot be an empty string or token at the end of the token stream, we will instead try to access the string value of the tail node of the linked list. That tail node has a value of null, boom, TypeError.
Example:
Prism.languages.test = {
'oh-no': {
pattern: /$/,
greedy: true
}
}
Prism.highlight('foo', Prism.languages.test, 'test');This is not a high prior bug. This bug has been in Prism ever since greedy matching was introduced and nobody noticed up until now.
Reactions are currently unavailable
