From 28011cbe0382c3b19bacaaad56bf6477e0265964 Mon Sep 17 00:00:00 2001 From: macchiati Date: Tue, 30 Jul 2024 09:29:16 -0700 Subject: [PATCH] CLDR-17847 Fix NPE in CodePointEscaper --- .../org/unicode/cldr/util/CodePointEscaper.java | 3 ++- .../unittest/UnicodeSetPrettyPrinterTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CodePointEscaper.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CodePointEscaper.java index 2446f3ca1a6..711d16895fa 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CodePointEscaper.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CodePointEscaper.java @@ -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 diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/UnicodeSetPrettyPrinterTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/UnicodeSetPrettyPrinterTest.java index 71700156807..c8d1d1da369 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/UnicodeSetPrettyPrinterTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/UnicodeSetPrettyPrinterTest.java @@ -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))); + } + } + } }