jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1188590 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/util/Text.java test/java/org/apache/jackrabbit/util/TextTest.java
Date Tue, 25 Oct 2011 10:11:32 GMT
Author: jukka
Date: Tue Oct 25 10:11:32 2011
New Revision: 1188590

URL: http://svn.apache.org/viewvc?rev=1188590&view=rev
Log:
JCR-3128: Problem with formerly escaped JCR node names when upgrading to Jackrabbit 2.2.9

Add a Text.escapeIllegalJcr10Chars method

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=1188590&r1=1188589&r2=1188590&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
Tue Oct 25 10:11:32 2011
@@ -464,14 +464,40 @@ public class Text {
      * @return the escaped name
      */
     public static String escapeIllegalJcrChars(String name) {
+        return escapeIllegalChars(name, "%/:[]*|\t\r\n");
+    }
+
+    /**
+     * Escapes all illegal JCR 1.0 name characters of a string.
+     * Use {@link #unescapeIllegalJcrChars(String)} for decoding.
+     * <p>
+     * QName EBNF:<br>
+     * <xmp>
+     * simplename ::= onecharsimplename | twocharsimplename | threeormorecharname
+     * onecharsimplename ::= (* Any Unicode character except: '.', '/', ':', '[', ']', '*',
''', '"', '|' or any whitespace character *)
+     * twocharsimplename ::= '.' onecharsimplename | onecharsimplename '.' | onecharsimplename
onecharsimplename
+     * threeormorecharname ::= nonspace string nonspace
+     * string ::= char | string char
+     * char ::= nonspace | ' '
+     * nonspace ::= (* Any Unicode character except: '/', ':', '[', ']', '*', ''', '"', '|'
or any whitespace character *)
+     * </xmp>
+     *
+     * @since Apache Jackrabbit 2.3.2 and 2.2.10
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-3128">JCR-3128</a>
+     * @param name the name to escape
+     * @return the escaped name
+     */
+    public static String escapeIllegalJcr10Chars(String name) {
+        return escapeIllegalChars(name, "%/:[]*'\"|\t\r\n");
+    }
+
+    private static String escapeIllegalChars(String name, String illegal) {
         StringBuilder buffer = new StringBuilder(name.length() * 2);
         for (int i = 0; i < name.length(); i++) {
             char ch = name.charAt(i);
-            if (ch == '%' || ch == '/' || ch == ':' || ch == '[' || ch == ']'
-                || ch == '*' || ch == '|'
-                || (ch == '.' && name.length() < 3)
-                || (ch == ' ' && (i == 0 || i == name.length() - 1))
-                || ch == '\t' || ch == '\r' || ch == '\n') {
+            if (illegal.indexOf(ch) != -1
+                    || (ch == '.' && name.length() < 3)
+                    || (ch == ' ' && (i == 0 || i == name.length() - 1))) {
                 buffer.append('%');
                 buffer.append(Character.toUpperCase(Character.forDigit(ch / 16, 16)));
                 buffer.append(Character.toUpperCase(Character.forDigit(ch % 16, 16)));

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=1188590&r1=1188589&r2=1188590&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
Tue Oct 25 10:11:32 2011
@@ -182,11 +182,17 @@ public class TextTest extends TestCase {
             fail("Text.unescape(" + string + "): " + unexpected.getMessage());
         }
     }
-        
-    public void testEscapeIllegalJcrChars() throws Exception {
 
+    public void testEscapeIllegalJcr10Chars() throws Exception {
+        // single and double quote are illegal in JCR 1.0
+        assertEquals("local%27name", Text.escapeIllegalJcr10Chars("local'name"));
+        assertEquals("local%22name", Text.escapeIllegalJcr10Chars("local\"name"));
+    }
+
+    public void testEscapeIllegalJcrChars() throws Exception {
         // single and double quote are valid since JCR 2.0
         assertEquals("local'name", Text.escapeIllegalJcrChars("local'name"));
-        assertEquals("local\"name", Text.escapeIllegalJcrChars("local\"name"));       
+        assertEquals("local\"name", Text.escapeIllegalJcrChars("local\"name"));
     }
+
 }



Mime
View raw message