jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r928888 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java
Date Mon, 29 Mar 2010 20:06:55 GMT
Author: mreutegg
Date: Mon Mar 29 20:06:54 2010
New Revision: 928888

URL: http://svn.apache.org/viewvc?rev=928888&view=rev
Log:
JCR-2558: UserManager.getAuthorizable() may fail with InvalidQueryException

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java?rev=928888&r1=928887&r2=928888&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
Mon Mar 29 20:06:54 2010
@@ -139,7 +139,7 @@ class IndexNodeResolver extends NodeReso
                 stmt.append(ISO9075.encode(pName));
                 if (exact) {
                     stmt.append("='");
-                    stmt.append(value);
+                    stmt.append(value.replaceAll("'", "''"));
                     stmt.append("'");
                 } else {
                     stmt.append(",'%");
@@ -164,7 +164,7 @@ class IndexNodeResolver extends NodeReso
             if (c == '\\') {
                 ret.append("\\\\");
             } else if (c == '\'') {
-                ret.append("\\'");
+                ret.append("''");
             } else {
                 ret.append(c);
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java?rev=928888&r1=928887&r2=928888&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/IndexNodeResolverTest.java
Mon Mar 29 20:06:54 2010
@@ -62,4 +62,47 @@ public class IndexNodeResolverTest exten
             save();
         }
     }
+
+    public void testFindNodesNonExactWithApostrophe()
+            throws NotExecutableException, RepositoryException {
+        UserImpl currentUser = getCurrentUser();
+        Value vs = superuser.getValueFactory().createValue("value ' with apostrophe");
+        currentUser.setProperty(propertyName1, vs);
+        save();
+
+        Name propName = ((SessionImpl) superuser).getQName(propertyName1);
+        try {
+            NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
+
+            NodeIterator result = nr.findNodes(propName, "value ' with apostrophe", UserConstants.NT_REP_USER,
false);
+            assertTrue("expected result", result.hasNext());
+            assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
+            assertFalse("expected no more results", result.hasNext());
+        } finally {
+            currentUser.removeProperty(propertyName1);
+            save();
+        }
+    }
+
+
+    public void testFindNodesExactWithApostrophe()
+            throws NotExecutableException, RepositoryException {
+        UserImpl currentUser = getCurrentUser();
+        Value vs = superuser.getValueFactory().createValue("value ' with apostrophe");
+        currentUser.setProperty(propertyName1, vs);
+        save();
+
+        Name propName = ((SessionImpl) superuser).getQName(propertyName1);
+        try {
+            NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
+
+            NodeIterator result = nr.findNodes(propName, "value ' with apostrophe", UserConstants.NT_REP_USER,
true);
+            assertTrue("expected result", result.hasNext());
+            assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
+            assertFalse("expected no more results", result.hasNext());
+        } finally {
+            currentUser.removeProperty(propertyName1);
+            save();
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message