Adding a test, and code fix, to have supplementary chars working in numeric entity unescaping. See LANG-617

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@956787 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-06-22 06:34:18 +00:00
parent c0041cafc2
commit bef3eb6ed0
2 changed files with 43 additions and 2 deletions

View File

@ -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;

View File

@ -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);
}
}