[java] Fix By.name() double String.format on names containing '%' - #17888
Conversation
PR Summary by QodoFix By.name() CSS fallback formatting for names containing '%'
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTo customize comments, go to the Qodo configuration screen, or learn more in the docs. Previous review resultsReview updated until commit 2b716ca Results up to commit 671f528
|
671f528 to
2b716ca
Compare
|
Code review by qodo was updated up to the latest commit 2b716ca |
🔗 Related Issues
Fixes #17807
💥 What does this PR do?
By.name(name)pre-substituted the name into the CSS pattern withString.format, thenPreW3CLocatorranString.formatover the result a second time. A%in the name (valid inHTML
nameattributes, e.g.name="50%off") was then read as a format conversion on the secondpass — throwing
IllegalFormatConversionException/UnknownFormatConversionExceptionatconstruction, or silently corrupting the fallback selector for inputs like
foo%sbar(
*[name='foofoo\%sbarbar']). The name is now concatenated in and any%is doubled so thesecond format pass treats it as a literal.
🔧 Implementation Notes
Kept the fix minimal and behavior-preserving rather than routing the name through
cssEscape.cssEscapeis identifier escaping (for.class/#id) and would over-escape an attribute-valuestring — e.g.
By.name("5foo")would become*[name='\35 foo']. Doubling%only changesbehavior for names containing
%, which previously threw or corrupted, so no valid existingselector changes.
This is Java-specific: it stems from Java's
String.format. Other bindings build the sameselector without a printf pass and are unaffected. Follow-up (separate issue): the W3C remote
codec's
namehandler inW3CHttpCommandCodecdoes no escaping of the name at all (not even').🤖 AI assistance
regression tests, authored the fix, verified via Bazel and google-java-format.
🔄 Types of changes