Repository navigation
Blink: match PHP-CS-Fixer on escapes and dollar signs in SingleQuote - #418
Merged
TomasVotruba merged 1 commit intoNov 20, 2026
Merged
Conversation
SingleQuote kept every double-quoted string holding a $ or a backslash.
PHP-CS-Fixer's SingleQuoteFixer converts any T_CONSTANT_ENCAPSED_STRING
whose only escape sequences are \\, \" and \$ (and that holds no single
quote, by default), unescaping \" and \$, so "/^\\d{2,}$/" becomes
'/^\\d{2,}$/'. Blink now applies the same checks, and ports the fixer's
upstream test cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TomasVotruba
approved these changes
Nov 20, 2026
Member
|
Thank you 👏 |
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.
Problem:
SingleQuotekept every double-quoted string holding a$or a backslash. PHP-CS-Fixer converts the ones whose only escapes are\\,\"and\$:SingleQuoteFixeronly looks atT_CONSTANT_ENCAPSED_STRINGtokens (L89-L92), so PHP's tokenizer has already decided that no$in them starts a variable. It keeps double quotes when the string holds a'(unlessstrings_containing_single_quote_charsis on) or when(?<!\\)(?:\\{2})*\\(?!["$\\])finds a backslash escaping anything but\,"or$(L102-L107), then unescapes\"and\$and escapes'(L108-L110).Change: the rule now gates on
aliasIsConstantString, which also rules out"${name}"(one String token in blink, not a constant string in PHP), mirrors the regex with a scan of the backslashes, and applies the same replacements.Tests: the 32 cases of PHP-CS-Fixer's
SingleQuoteFixerTestand 9 more (a$that starts no variable,\$,\",\\before escape letters, the other escape sequences, interpolation, the binary prefix, an unterminated literal). Expected output from PHP-CS-Fixer 3.95.32; 11 of the 41 fail onmain.Parity: on a private Symfony codebase (10,390 files, plus 792 files of it before it was formatted), blink and the PHP engine differed in 7 files for this rule; with this change, 0, and no new difference with the rule alone or the full
@Symfonyset. On a 26,000-filevendor/tree: 99 files, now 0.🤖 Generated with Claude Code (Opus 5.5)