Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📜 Recent review details🧰 Additional context used🧠 Learnings (7)📚 Learning: 2026-04-21T21:24:32.138ZApplied to files:
📚 Learning: 2026-06-05T13:48:39.340ZApplied to files:
📚 Learning: 2026-06-07T20:07:07.417ZApplied to files:
📚 Learning: 2026-07-06T14:24:20.463ZApplied to files:
📚 Learning: 2026-04-11T18:58:31.942ZApplied to files:
📚 Learning: 2026-04-14T10:43:29.381ZApplied to files:
📚 Learning: 2026-05-01T02:09:33.591ZApplied to files:
🪛 PHPMD (2.15.0)tests/framework/helpers/HtmlTest.php[error] 2150-2150: Avoid using static access to class '\yii\helpers\Html' in method 'testEscapeJsRegularExpressionBracketStyleDelimiters'. (undefined) (StaticAccess) [error] 2173-2173: Avoid using static access to class '\yii\helpers\Html' in method 'testEscapeJsRegularExpressionHexEscapes'. (undefined) (StaticAccess) 🔇 Additional comments (3)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesRegular Expression Escaping
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21052 +/- ##
=============================================
- Coverage 80.69% 30.97% -49.72%
- Complexity 11552 11554 +2
=============================================
Files 374 374
Lines 30280 30279 -1
=============================================
- Hits 24435 9380 -15055
- Misses 5845 20899 +15054 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
97db1af to
173fc31
Compare
…le delimiters in Html::escapeJsRegularExpression()
173fc31 to
176accc
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Two separate defects in
escapeJsRegularExpression(). They're in adjacent lines of the same short method, so I put them in one PR rather than have the second one conflict with the first.Hex escapes (#20322)
A JavaScript
\uescape takes exactly four hex digits. The replacement didn't pad, so\xFFcame out as\uFF, which JS reads as\u00followed by a literalF. Two more problems in the same line:[0-9a-fA-F]+is greedy while PCRE reads at most two digits without braces, so\x41abcswallowed theabc; and code points above the BMP need the\u{...}form, which the old code never produced./^[\x00-\xFF]{8,72}$//^[\u00-\uFF]{8,72}$//^[\u0000-\u00FF]{8,72}$//^[\x{A1}-\x{FE}]{2}$/u/^[\uA1-\uFE]{2}$/u/^[\u00A1-\u00FE]{2}$/u/\x41abc//\u41abc//\u0041abc//[\x{1F600}-\x{1F64F}]/u/[\u1F600-\u1F64F]/u/[\u{1F600}-\u{1F64F}]/uThe
\u{...}form needs theuflag, which the existing modifier filter already keeps. The second row is the case raised in #20330.Bracket style delimiters (#20456)
The end of the pattern is found by searching for the last occurrence of the delimiter. That's fine for
/,#or~, but PHP also allows the pairs(),{},[]and<>, which are closed by the matching bracket. So the search lands in the middle of the pattern and the rest is cut off:{^\d{3}$}/^\d//^\d{3}$/(^(\d+)(\.\d+)?$)/^(\d+)//^(\d+)(\.\d+)?$/<^[a-z]+$>i/^[a-z]+$>/i/^[a-z]+$/i[^[a-z]+$]/^//^[a-z]+$/Either way the result is a regex that no longer means what the server-side rule means, so client-side validation quietly accepts values the server rejects.
One note on #20456
The report gives
([a-z_])([a-z0-9_])*as input and expects/([a-z_])([a-z0-9_])*/. That input isn't a valid PCRE pattern: with(as the delimiter the matching)closes it right after[a-z_], and the rest is parsed as modifiers, sopreg_match()errors out. Producing the expected output would mean treating a delimiter-less string as the pattern body, which is not what any caller passes in and would change the existing('([a-z0-9-]+)')assertion. Happy to look at that separately if you want the helper to accept those too.I also added a sentence to the PHPDoc saying the argument is expected to be a valid PCRE pattern, since that was never written down.