jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r732703 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/util/Text.java test/java/org/apache/jackrabbit/util/TextTest.java
Date Thu, 08 Jan 2009 13:36:05 GMT
Author: jukka
Date: Thu Jan  8 05:36:05 2009
New Revision: 732703

URL: http://svn.apache.org/viewvc?rev=732703&view=rev
Log:
JCR-1926: Text.unescape("%") throws a StringIndexOutOfBoundsException 

Now throws IllegalArgumentException. Also added a relevant test case.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java?rev=732703&r1=732702&r2=732703&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Thu Jan  8 05:36:05 2009
@@ -402,15 +402,19 @@
         ByteArrayOutputStream out = new ByteArrayOutputStream(string.length());
         for (int i = 0; i < string.length(); i++) {
             char c = string.charAt(i);
-            if (c == escape) {
+            if (c != escape) {
+                out.write(c);
+            } else if (i + 2 < string.length()) {
                 try {
                     out.write(Integer.parseInt(string.substring(i + 1, i + 3), 16));
                 } catch (NumberFormatException e) {
-                    throw new IllegalArgumentException();
+                    throw new IllegalArgumentException(
+                            "Escape sequence is not hexadecimal: " + string);
                 }
                 i += 2;
             } else {
-                out.write(c);
+                throw new IllegalArgumentException(
+                        "Escape sequence is too short: " + string);
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java?rev=732703&r1=732702&r2=732703&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
Thu Jan  8 05:36:05 2009
@@ -143,4 +143,23 @@
             assertEquals(strs[1], Text.getName(strs[0], '='));
         }
     }
+
+    /**
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1926">JCR-1926</a>
+     */
+    public void testUnescapeWithInvalidInput() {
+        assertInvalidUnescape("%");   // too short
+        assertInvalidUnescape("%%");  // too short
+        assertInvalidUnescape("%%%"); // not a number
+    }
+
+    private void assertInvalidUnescape(String string) {
+        try {
+            Text.unescape(string);
+        } catch (IllegalArgumentException expected) {
+        } catch (RuntimeException unexpected) {
+            fail("Text.unescape(" + string + "): " + unexpected.getMessage());
+        }
+    }
+
 }



Mime
View raw message