chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1700589 - in /chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src: main/java/org/apache/chemistry/opencmis/client/runtime/ test/java/org/apache/chemistry/opencmis/client/runtime/
Date Tue, 01 Sep 2015 15:26:08 GMT
Author: fmui
Date: Tue Sep  1 15:26:08 2015
New Revision: 1700589

URL: http://svn.apache.org/r1700589
Log:
CMIS-946: fixed escaping of CONTAINS queries

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java?rev=1700589&r1=1700588&r2=1700589&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
Tue Sep  1 15:26:08 2015
@@ -643,9 +643,7 @@ public class QueryStatementImpl implemen
     }
 
     private static String escapeContains(String str) {
-        StringBuilder sb = new StringBuilder(str.length() + 16);
-
-        sb.append('\'');
+        StringBuilder sb = new StringBuilder(str.length() + 64);
 
         for (int i = 0; i < str.length(); i++) {
             char c = str.charAt(i);
@@ -653,15 +651,22 @@ public class QueryStatementImpl implemen
             if (c == '\\') {
                 sb.append('\\');
             } else if (c == '\'' || c == '\"') {
-                sb.append("\\\\\\");
+                sb.append('\\');
+            } else if (c == '-') {
+                if (i > 0) {
+                    char cb = str.charAt(i - 1);
+                    if (cb == '\\') {
+                        sb.deleteCharAt(sb.length() - 1);
+                    } else if (cb != ' ') {
+                        sb.append('\\');
+                    }
+                }
             }
 
             sb.append(c);
         }
 
-        sb.append('\'');
-
-        return sb.toString();
+        return escape(sb.toString());
     }
 
     private static String convert(Date date) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java?rev=1700589&r1=1700588&r2=1700589&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
Tue Sep  1 15:26:08 2015
@@ -99,6 +99,10 @@ public class QueryStatementTest {
         st = new QueryStatementImpl(session, query);
         st.setStringContains(1, "John's");
         assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('John\\\\\\'s')", st.toQueryString());
+        st.setStringContains(1, "John'sPresentation-Version2");
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('John\\\\\\'sPresentation\\\\-Version2')",
st.toQueryString());
+        st.setStringContains(1, "search\\'");
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('search\\\\\\\\\\\\\\'')",
st.toQueryString());
         st.setStringContains(1, "foo -bar");
         assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo -bar')", st.toQueryString());
         st.setStringContains(1, "foo*");
@@ -108,13 +112,13 @@ public class QueryStatementTest {
         st.setStringContains(1, "foo\\-bar");
         assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\-bar')", st.toQueryString());
         st.setStringContains(1, "foo\\*");
-        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\*')", st.toQueryString());
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\\\\\*')", st.toQueryString());
         st.setStringContains(1, "foo\\?");
-        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\?')", st.toQueryString());
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\\\\\?')", st.toQueryString());
         st.setStringContains(1, "\"Cool\"");
-        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('\\\\\\\"Cool\\\\\\\"')",
st.toQueryString());
-        st.setStringContains(1, "c:\\MyDcuments");
-        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('c:\\\\MyDcuments')", st.toQueryString());
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('\\\\\"Cool\\\\\"')", st.toQueryString());
+        st.setStringContains(1, "c:\\MyDocuments");
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('c:\\\\\\\\MyDocuments')",
st.toQueryString());
 
         // ids
         query = "SELECT * FROM cmis:document WHERE abc:id = ?";



Mime
View raw message