lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r886155 - in /lucene/solr/trunk: CHANGES.txt src/java/org/apache/solr/search/QueryParsing.java src/test/org/apache/solr/search/TestQueryTypes.java
Date Wed, 02 Dec 2009 14:28:38 GMT
Author: yonik
Date: Wed Dec  2 14:28:38 2009
New Revision: 886155

URL: http://svn.apache.org/viewvc?rev=886155&view=rev
Log:
SOLR-1615: fix StrParser quoted string backslash escaping, add java-style unicode escaping

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java
    lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=886155&r1=886154&r2=886155&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Wed Dec  2 14:28:38 2009
@@ -104,6 +104,10 @@
 
 * SOLR-1601: Schema browser does not indicate presence of charFilter. (koji)
 
+* SOLR-1615: Backslash escaping did not work in quoted strings
+  for local param arguments. (Wojtek Piaseczny, yonik)
+
+
 Other Changes
 ----------------------
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java?rev=886155&r1=886154&r2=886155&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java Wed Dec  2 14:28:38
2009
@@ -625,14 +625,32 @@
         }
         char ch = val.charAt(pos);
         if (ch=='\\') {
-          ch = pos<end ? val.charAt(pos++) : 0;
-        } else if (ch==delim) {
           pos++;
-          return sb.toString();
+          if (pos>=end) break; 
+          ch = val.charAt(pos);
+          switch(ch) {
+            case 'n' : ch='\n'; break;
+            case 't' : ch='\t'; break;
+            case 'r' : ch='\r'; break;
+            case 'b' : ch='\b'; break;
+            case 'f' : ch='\f'; break;
+            case 'u' :
+              if (pos+4 >= end) {
+                throw new ParseException("bad unicode escape \\uxxxx at pos" + (val_start-1)
+ " str='"+val+"'");                
+              }
+              ch = (char)Integer.parseInt(val.substring(pos+1, pos+5), 16);
+              pos += 4;
+              break;
+          }
+        } else if (ch==delim) {
+          pos++;  // skip over the quote
+          break;
         }
         sb.append(ch);
         pos++;
       }
+
+      return sb.toString();
     }
 
     // next non-whitespace char

Modified: lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java?rev=886155&r1=886154&r2=886155&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java Wed Dec  2 14:28:38
2009
@@ -46,6 +46,7 @@
     assertU(adoc("id","6", "v_f","8983"));
     assertU(adoc("id","7", "v_f","1.5"));
     assertU(adoc("id","8", "v_ti","5"));
+    assertU(adoc("id","9", "v_s","internal\"quote"));
 
     Object[] arr = new Object[] {
     "id",999.0
@@ -125,6 +126,34 @@
             ,"//result[@numFound='0']"
             );
 
+    //
+    // test escapes in quoted strings
+    //
+
+    // the control... unescaped queries looking for internal"quote
+    assertQ(req("q","{!raw f=v_s}internal\"quote")
+            ,"//result[@numFound='1']"
+            );
+
+    // test that single quoted string needs no escape
+    assertQ(req("q","{!raw f=v_s v='internal\"quote'}")
+            ,"//result[@numFound='1']"
+            );
+
+    // but it's OK if the escape is done
+    assertQ(req("q","{!raw f=v_s v='internal\\\"quote'}")
+            ,"//result[@numFound='1']"
+            );
+
+    // test unicode escape
+    assertQ(req("q","{!raw f=v_s v=\"internal\\u0022quote\"}")
+            ,"//result[@numFound='1']"
+            );
+
+    // inside a quoted string, internal"quote needs to be escaped
+    assertQ(req("q","{!raw f=v_s v=\"internal\\\"quote\"}")
+            ,"//result[@numFound='1']"
+            );
 
     assertQ("test custom plugin query",
             req("q","{!foo f=v_t}hello")



Mime
View raw message