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

PHP: Fixed exponential runtime of a pattern #2157

Merged
merged 3 commits into from Jan 5, 2020

Conversation

RunDevelopment
Copy link
Member

This fixes the exponential runtime of the pattern used to identify PHP code embedded in HTML. (This resolves #2156.)

The problem was that the alternative for single-line comments (?:\/\/|#)(?:[^?\n\r]|\?(?!>))* was open-ended, so the regex engine could decide how many characters to match. The fix is that I added a lookahead which enforces that these comments end at either the end of a line of the end of the PHP code block.

@mAAdhaTTah
Copy link
Member

Can we add a test to cover this scenario?

@RunDevelopment
Copy link
Member Author

I didn't because the code is syntactically invalid which caused the exponential run time in the first place.
So what do we want to test?

@mAAdhaTTah
Copy link
Member

Can we add a test with the invalid code and ensure it completes? Even if the token stream is an empty array, it will still verify the bug is fixed (and not potentially reintroduced).

@RunDevelopment
Copy link
Member Author

Added the test. It's parsed as an XML prolog.

@RunDevelopment RunDevelopment merged commit 24c8f83 into PrismJS:master Jan 5, 2020
@RunDevelopment RunDevelopment deleted the php-pattern-fix branch January 5, 2020 18:56
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.

Endless loop with invalid PHP code
2 participants