Conversation
This commit fixes a bug which could lead to a `Fatal error: Uncaught ValueError: Unknown format specifier "D"`.
Analysis of the bug:
1. The original regex did not "remember" the chars before/after the targeted `%` sign, but the replacement is being done on the complete match, including those chars, not only on the `%` chars.
2. Once that is fixed and the char before and after the `%` sign are now a) remembered and b) included in the replacement, the next problem becomes clear: the regex engine involves characters only in **_one_** match.
This means that for a string like this: `C%D%E%F`, the `C%D` would become the first match. As the `D` was included in the first match, the regex engine only continues searching _after_, so the next match will be `E%F`, but the `D%E` would not be matched.
3. To fix that, we execute the regex search & replace twice. This is safe to do as the original regex already contained protection against double escaping.
Includes tests.
Note: while the test now added would have caught this issue due to the fatal error, the _original_ tests for this issue on line 85 - 93 of the same test file suffered from the same problem. The reason this was not caught via the tests, is because the test framework doesn't check the actual error messages, only the fact that an error is thrown (and fixed correctly).
It is the intention to at some point change this via a better base test class in PHPCSUtils, but for now, this will have to do.
Fixes 400
bebe01c to
0177e9c
Compare
|
This fixes the issue I reported! |
Member
Author
|
Thanks for testing @westonruter ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes a bug which could lead to a
Fatal error: Uncaught ValueError: Unknown format specifier "D".Analysis of the bug:
%sign, but the replacement is being done on the complete match, including those chars, not only on the%chars.%sign are now a) remembered and b) included in the replacement, the next problem becomes clear: the regex engine involves characters only in one match. This means that for a string like this:C%D%E%F, theC%Dwould become the first match. As theDwas included in the first match, the regex engine only continues searching after, so the next match will beE%F, but theD%Ewould not be matched.Includes tests.
Note: while the test now added would have caught this issue due to the fatal error, the original tests for this issue on line 85 - 93 of the same test file suffered from the same problem. The reason this was not caught via the tests, is because the test framework doesn't check the actual error messages, only the fact that an error is thrown (and fixed correctly).
It is the intention to at some point change this via a better base test class in PHPCSUtils, but for now, this will have to do.
Fixes #400