Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fixed type error on null #3057

Merged
merged 2 commits into from Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/prism-core.js
Expand Up @@ -926,7 +926,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 @@ -979,7 +979,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 @@ -931,7 +931,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']
});
});

});