diff --git a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java index 12a066387..a21671a78 100644 --- a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java +++ b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java @@ -60,8 +60,13 @@ public class NumericEntityUnescaper extends CharSequenceTranslator { return 0; } - // TODO: if(entityValue > 0xFFFF) { - out.write(entityValue); + if(entityValue > 0xFFFF) { + char[] chrs = Character.toChars(entityValue); + out.write(chrs[0]); + out.write(chrs[1]); + } else { + out.write(entityValue); + } return 2 + (end - start) + (isHex ? 1 : 0) + 1; } return 0; diff --git a/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java new file mode 100644 index 000000000..3ea7138a7 --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang3.text.translate; + +import junit.framework.TestCase; + +/** + * Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}. + */ +public class NumericEntityUnescaperTest extends TestCase { + + public void testSupplementaryUnescaping() { + NumericEntityUnescaper neu = new NumericEntityUnescaper(); + String input = "𐰢"; + String expected = "\uD803\uDC22"; + + String result = neu.translate(input); + assertEquals("Failed to unescape numeric entities supplementary characters", expected, result); + } + +}