Skip to content

Commit

Permalink
CLDR-17847 Fix NPE in CodePointEscaper
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati committed Jul 30, 2024
1 parent 31cdf11 commit 28011cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ public static String toUnescaped(String escaped) {
public static String toExample(int codePoint) {
CodePointEscaper cpe = _fromCodePoint.get(codePoint);
if (cpe == null) { // hex
final String name = UCharacter.getExtendedName(codePoint);
return codePointToEscaped(codePoint)
+ HAS_NAME
+ UCharacter.getName(codePoint).toLowerCase();
+ (name != null ? name.toLowerCase() : "");
} else {
return CodePointEscaper.codePointToEscaped(cpe.codePoint)
+ HAS_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,19 @@ public void TestStringEscaper() {
assertEquals(expected, expectedRoundtrip, actualRoundtrip);
}
}

public void test17847() {
String path =
"//ldml/characters/parseLenients[@scope=\"general\"][@level=\"lenient\"]/parseLenient[@sample=\"$\"]";
String value = "[\\$$﹩ \\uFFFF]";
UnicodeSet valueSet = new UnicodeSet(value).freeze();
UnicodeSet examples = new UnicodeSet();

// throws exception
if (valueSet.containsSome(CodePointEscaper.FORCE_ESCAPE)) {
for (String nsm : new UnicodeSet(valueSet).retainAll(CodePointEscaper.FORCE_ESCAPE)) {
assertNotNull(Utility.hex(nsm), CodePointEscaper.toExample(nsm.codePointAt(0)));
}
}
}
}

0 comments on commit 28011cb

Please sign in to comment.