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.
So I just found this bug. If a greedy token creates an empty match
mat the end of the string (m = re.exec(text); m[0] == "" && m.index == text.length), thenmatchGrammarwill 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 ofnull, boom, TypeError.Example:
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.