jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r792588 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/user/ test/java/org/apache/jackrabbit/core/security/user/
Date Thu, 09 Jul 2009 15:47:17 GMT
Author: angela
Date: Thu Jul  9 15:47:16 2009
New Revision: 792588

URL: http://svn.apache.org/viewvc?rev=792588&view=rev
Log:
JCR-2202: UserManagement: IndexNodeResolver.findNodes(..... , nonExact) fails to find values
containing backslash

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
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.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=792588&r1=792587&r2=792588&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
Thu Jul  9 15:47:16 2009
@@ -95,7 +95,7 @@
      */
     private Query buildQuery(Name nodeName, Name ntName)
             throws RepositoryException {
-        StringBuffer stmt = new StringBuffer("/jcr:root");
+        StringBuilder stmt = new StringBuilder("/jcr:root");
         stmt.append(getSearchRoot(ntName));
         stmt.append("//element(");
         stmt.append(ISO9075.encode(getNamePathResolver().getJCRName(nodeName)));
@@ -118,7 +118,7 @@
     private Query buildQuery(String value, Set props, Name ntName,
                              boolean exact, long maxSize)
             throws RepositoryException {
-        StringBuffer stmt = new StringBuffer("/jcr:root");
+        StringBuilder stmt = new StringBuilder("/jcr:root");
         stmt.append(getSearchRoot(ntName));
         stmt.append("//element(*,");
         stmt.append(getNamePathResolver().getJCRName(ntName));
@@ -133,9 +133,15 @@
                 stmt.append((exact) ? "@" : "jcr:like(@");
                 String pName = getNamePathResolver().getJCRName((Name) itr.next());
                 stmt.append(ISO9075.encode(pName));
-                stmt.append((exact) ? "='" : ",'%");
-                stmt.append(value);
-                stmt.append((exact) ? "'" : "%')");
+                if (exact) {
+                    stmt.append("='");
+                    stmt.append(value);
+                    stmt.append("'");
+                } else {
+                    stmt.append(",'%");
+                    stmt.append(escapeForQuery(value));
+                    stmt.append("%')");
+                }
                 if (++i < props.size()) {
                     stmt.append(" or ");
                 }
@@ -146,4 +152,19 @@
         q.setLimit(maxSize);
         return q;
     }
+
+    private static String escapeForQuery(String value) {
+        StringBuilder ret = new StringBuilder();
+        for (int i = 0; i < value.length(); i++) {
+            char c = value.charAt(i);
+            if (c == '\\') {
+                ret.append("\\\\");
+            } else if (c == '\'') {
+                ret.append("\\'");
+            } else {
+                ret.append(c);
+            }
+        }
+        return ret.toString();
+    }
 }

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=792588&r1=792587&r2=792588&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
Thu Jul  9 15:47:16 2009
@@ -18,11 +18,14 @@
 
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.NodeIterator;
 
 /** <code>IndexNodeResolver</code>... */
 public class IndexNodeResolverTest extends NodeResolverTest {
@@ -35,4 +38,30 @@
         }
         return new IndexNodeResolver(session, (SessionImpl) session);
     }
+
+
+    /**
+     * If query value contains backslash the non-exact findNodes method should
+     * return the desired result.
+     *
+     * @throws NotExecutableException
+     * @throws RepositoryException
+     */
+    public void testFindNodesNonExact() throws NotExecutableException, RepositoryException
{
+        UserImpl currentUser = getCurrentUser(superuser);
+        Value vs = superuser.getValueFactory().createValue("value \\, containing backslash");
+        currentUser.setProperty(propertyName1, vs);
+
+        Name propName = ((SessionImpl) superuser).getQName(propertyName1);
+        try {
+            NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
+
+            NodeIterator result = nr.findNodes(propName, "value \\, containing backslash",
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);
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java?rev=792588&r1=792587&r2=792588&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java
Thu Jul  9 15:47:16 2009
@@ -48,7 +48,7 @@
         nodeResolver = createNodeResolver(superuser);
     }
 
-    private static UserImpl getCurrentUser(Session session) throws NotExecutableException,
RepositoryException {
+    protected static UserImpl getCurrentUser(Session session) throws NotExecutableException,
RepositoryException {
         if (!(session instanceof JackrabbitSession)) {
             throw new NotExecutableException();
         }



Mime
View raw message