Add CRLF test case for EregToPregMatchRector #6245
Closed
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.
EregToPregMatchRector
(andEregToPcreTransformer
) convert ereg regular expression strings that contain CR or LF characters (i.e., double-quoted strings with\r
or\n
) to preg regular expression strings that are single-quoted but contain the unescaped character (i.e., multi-line string literal with embedded CR or LF characters).Example:
... becomes ...
(The CR is invisible in the second statement in the output, so it looks like a duplicate of the first statement.)
This transformation complies with PHP syntax, and the preg functions treat
"#\r#"
as equivalent to'#\r#'
. The problem occurs when git and its autocrlf behavior removes CR characters without regard to them being embedded in multi-line strings. This results in a platform-dependent regular expression, when the original source code avoided that behavior.Even though this is clearly a caveat developer situation, it would be nice if the
EregToPregMatchRector
rule could try to preserve the original representation. Converting the double-quoted string to a suitable single-quoted PCRE regular expression would be ideal, but probably too error prone.