You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2010/06/22 08:34:18 UTC

svn commit: r956787 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java

Author: bayard
Date: Tue Jun 22 06:34:18 2010
New Revision: 956787

URL: http://svn.apache.org/viewvc?rev=956787&view=rev
Log:
Adding a test, and code fix, to have supplementary chars working in numeric entity unescaping. See LANG-617

Added:
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java   (with props)
Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java?rev=956787&r1=956786&r2=956787&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java Tue Jun 22 06:34:18 2010
@@ -60,8 +60,13 @@ public class NumericEntityUnescaper exte
                 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;

Added: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java?rev=956787&view=auto
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java (added)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java Tue Jun 22 06:34:18 2010
@@ -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);
+    }
+
+}

Propchange: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native