You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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+212A → k, 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.
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?
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.
Done: apache/commons-text#762, same toLowerCase fold plus the Kelvin/Angstrom regression assertions in TextStringBuilderTest.
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
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.
Repro:new StrBuilder("K").equalsIgnoreCase(new StrBuilder("K"))(KELVIN SIGN vsK) returnsfalse, and so does the å/ANGSTROM pairnew StrBuilder("å").equalsIgnoreCase(new StrBuilder("Å")).String.equalsIgnoreCasereturnstruefor both.Cause: the per-character loop only rules a differing pair equal whenCharacter.toUpperCase(c1) == Character.toUpperCase(c2). Characters that fold together only through their lower-case mapping (U+212A→k,U+212B→å) fail that test, so the whole compare reports not-equal.Fix: also accept the pair whenCharacter.toLowerCaseof the upper-cased chars agrees, the same foldString#regionMatchesand this library's ownCharSequenceUtils.equalsIgnoreCasealready use. The case-sensitiveequalssibling is untouched.