commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1065215 - 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
Date Sun, 30 Jan 2011 08:01:20 GMT
Author: bayard
Date: Sun Jan 30 08:01:19 2011
New Revision: 1065215

URL: http://svn.apache.org/viewvc?rev=1065215&view=rev
Log:
Implemented TODO to protect unescaper from ArrayIndexOutOfBounds

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.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=1065215&r1=1065214&r2=1065215&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
Sun Jan 30 08:01:19 2011
@@ -34,8 +34,7 @@ public class NumericEntityUnescaper exte
      */
     @Override
     public int translate(CharSequence input, int index, Writer out) throws IOException {
-        // TODO: Protect from ArrayIndexOutOfBounds
-        if(input.charAt(index) == '&' && input.charAt(index + 1) == '#') {
+        if(input.charAt(index) == '&' && index < (input.length() - 1) &&
input.charAt(index + 1) == '#') {
             int start = index + 2;
             boolean isHex = false;
 

Modified: 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=1065215&r1=1065214&r2=1065215&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
Sun Jan 30 08:01:19 2011
@@ -34,4 +34,13 @@ public class NumericEntityUnescaperTest 
         assertEquals("Failed to unescape numeric entities supplementary characters", expected,
result);
     }
 
+    public void testOutOfBounds() {
+        NumericEntityUnescaper neu = new NumericEntityUnescaper();
+        String input = "Test &";
+        String expected = input;
+
+        String result = neu.translate(input);
+        assertEquals("Failed to ignore when last character is &", expected, result);
+    }
+
 }



Mime
View raw message