Skip to content

Match String case folding in StrBuilder.equalsIgnoreCase#1745

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:strbuilder-equalsignorecase-fold
Jul 11, 2026
Merged

Match String case folding in StrBuilder.equalsIgnoreCase#1745
garydgregory merged 1 commit into
apache:masterfrom
alhudz:strbuilder-equalsignorecase-fold

Conversation

@alhudz

@alhudz alhudz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Repro: new StrBuilder("K").equalsIgnoreCase(new StrBuilder("K")) (KELVIN SIGN vs K) returns false, and so does the å/ANGSTROM pair new StrBuilder("å").equalsIgnoreCase(new StrBuilder("Å")). String.equalsIgnoreCase returns true for both.

Cause: the per-character loop only rules a differing pair equal when Character.toUpperCase(c1) == Character.toUpperCase(c2). Characters that fold together only through their lower-case mapping (U+212Ak, U+212Bå) fail that test, so the whole compare reports not-equal.

Fix: also accept the pair when Character.toLowerCase of the upper-cased chars agrees, the same fold String#regionMatches and this library's own CharSequenceUtils.equalsIgnoreCase already use. The case-sensitive equals sibling is untouched.

@garydgregory garydgregory merged commit 7c91ce9 into apache:master Jul 11, 2026
20 of 21 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @alhudz , merged 🚀
Since this class is deprecated in Commons Lang (but bugs should still be fixed) in favor of Commons Text's TextStringBuilder, would you please verify parity there?

@alhudz

alhudz commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Checked, parity is not there. TextStringBuilder.equalsIgnoreCase has the same upper-case-only fold (line 1911 on current master).

Repro against commons-text 1.15.0: new TextStringBuilder("K").equalsIgnoreCase(new TextStringBuilder("K")) (KELVIN SIGN vs K) -> false while String -> true; same for å vs ANGSTROM SIGN Å -> false vs true. The same one-line toLowerCase fold from this PR fixes it there too.

Thanks for merging.

@garydgregory

Copy link
Copy Markdown
Member

Would you please create a PR for Commons Text?

@alhudz

alhudz commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Done: apache/commons-text#762, same toLowerCase fold plus the Kelvin/Angstrom regression assertions in TextStringBuilderTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants