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 greedy targeting bug #1932

Merged
merged 13 commits into from
Aug 29, 2019

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Jun 8, 2019

This PR fixes a bug of greedy matching.

The target parameter defines the token which causes rematching. Rematching is done by recursively calling matchGrammar where target will be the current token name. The rematching is done if either a match was found or we reached the target token, whatever comes first.

The bug is that a token is identified by its name. But the name alone doesn't uniquely identify a token in a grammar because many tokens can have the same name:

{
    'token': [
        /foo/,
        /bar/i
    ]
}

The fix is quite obvious. target will no be a combination of the token name and its index.

Note: This is a technically a breaking change because matchGrammar is publicly exposed. But the function is also not documented, so its behavior is undefined anyway.


Edit:
An example of the bug is the following JS code:

// /*

/* const

Before:
image

After:
image

@mAAdhaTTah
Copy link
Member

Possible to get tests that demonstrates the fixed behavior?

@RunDevelopment RunDevelopment merged commit e864d51 into PrismJS:master Aug 29, 2019
@RunDevelopment RunDevelopment deleted the greedy-target-fix branch August 29, 2019 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants