Core: Fixed type error on null (#3057)

This commit is contained in:
Michael Schmidt 2021-10-02 01:29:28 +02:00 committed by GitHub
parent 8daebb4ab9
commit a80a68ba50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 4 deletions

View File

@ -947,7 +947,7 @@ var Prism = (function (_self) {
if (greedy) {
match = matchPattern(pattern, pos, text, lookbehind);
if (!match) {
if (!match || match.index >= text.length) {
break;
}

File diff suppressed because one or more lines are too long

View File

@ -1000,7 +1000,7 @@ var Prism = (function (_self) {
if (greedy) {
match = matchPattern(pattern, pos, text, lookbehind);
if (!match) {
if (!match || match.index >= text.length) {
break;
}

View File

@ -952,7 +952,7 @@ var Prism = (function (_self) {
if (greedy) {
match = matchPattern(pattern, pos, text, lookbehind);
if (!match) {
if (!match || match.index >= text.length) {
break;
}

View File

@ -105,4 +105,18 @@ describe('Greedy matching', function () {
});
});
it('issue3052', function () {
// If a greedy pattern creates an empty token at the end of the string, then this token should be discarded
testTokens({
grammar: {
'oh-no': {
pattern: /$/,
greedy: true
}
},
code: 'foo',
expected: ['foo']
});
});
});