Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Core: Fixed type error on null (#3057)
  • Loading branch information
RunDevelopment committed Oct 1, 2021
1 parent 8daebb4 commit a80a68b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-core.js
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/prism-core.js.html
Expand Up @@ -1000,7 +1000,7 @@ <h1 class="page-title">prism-core.js</h1>

if (greedy) {
match = matchPattern(pattern, pos, text, lookbehind);
if (!match) {
if (!match || match.index >= text.length) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion prism.js
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/core/greedy.js
Expand Up @@ -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']
});
});

});

0 comments on commit a80a68b

Please sign in to comment.