commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1411850 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java test/java/org/apache/commons/lang3/StringUtilsTest.java
Date Tue, 20 Nov 2012 20:45:51 GMT
Author: ggregory
Date: Tue Nov 20 20:45:50 2012
New Revision: 1411850

URL: http://svn.apache.org/viewvc?rev=1411850&view=rev
Log:
[LANG-857] StringIndexOutOfBoundsException in CharSequenceTranslator.

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1411850&r1=1411849&r2=1411850&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml Tue Nov 20 20:45:50 2012
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.2" date="TBA" description="Next release">
+    <action issue="LANG-857" type="add">StringIndexOutOfBoundsException in CharSequenceTranslator</action>
     <action issue="LANG-856" type="add">Code refactoring in NumberUtils</action>
     <action issue="LANG-855" type="add">NumberUtils#createBigInteger does not allow
for hex and octal numbers</action>
     <action issue="LANG-854" type="add">NumberUtils#createNumber - does not allow for
hex numbers to be larger than Long</action>

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java?rev=1411850&r1=1411849&r2=1411850&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java
Tue Nov 20 20:45:50 2012
@@ -92,7 +92,7 @@ public abstract class CharSequenceTransl
 //          // contract with translators is that they have to understand codepoints 
 //          // and they just took care of a surrogate pair
             for (int pt = 0; pt < consumed; pt++) {
-                pos += Character.charCount(Character.codePointAt(input, pos));
+                pos += Character.charCount(Character.codePointAt(input, pt));
             }
         }
     }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=1411850&r1=1411849&r2=1411850&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Tue Nov 20 20:45:50 2012
@@ -2181,4 +2181,14 @@ public class StringUtilsTest {
         expectedBytes = expectedString.getBytes(encoding);
         assertEquals(expectedString, StringUtils.toString(expectedBytes, encoding));
     }
+    
+    @Test
+    public void testEscapeSurrogatePairs() throws Exception {
+        assertEquals("\uD83D\uDE30", StringEscapeUtils.escapeCsv("\uD83D\uDE30"));
+        // Examples from https://en.wikipedia.org/wiki/UTF-16
+        assertEquals("\uD800\uDC00", StringEscapeUtils.escapeCsv("\uD800\uDC00"));
+        assertEquals("\uD834\uDD1E", StringEscapeUtils.escapeCsv("\uD834\uDD1E"));
+        assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeCsv("\uDBFF\uDFFD"));
+        
+    }
 }



Mime
View raw message