lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r524524 - in /lucene/solr/trunk/src: test/org/apache/solr/servlet/SolrRequestParserTest.java webapp/src/org/apache/solr/servlet/SolrRequestParsers.java
Date Sun, 01 Apr 2007 03:43:43 GMT
Author: yonik
Date: Sat Mar 31 20:43:42 2007
New Revision: 524524

URL: http://svn.apache.org/viewvc?view=rev&rev=524524
Log:
fix queryString parsing to handle UTF8 (percent encoded): SOLR-202

Modified:
    lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
    lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java

Modified: lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java?view=diff&rev=524524&r1=524523&r2=524524
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java Sat Mar
31 20:43:42 2007
@@ -17,7 +17,6 @@
 
 package org.apache.solr.servlet;
 
-import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -25,20 +24,13 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.servlet.http.HttpServletRequestWrapper;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.solr.core.Config;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
-import org.apache.solr.util.ContentStream;
-import org.apache.solr.request.MapSolrParams;
 import org.apache.solr.request.MultiMapSolrParams;
 import org.apache.solr.request.SolrParams;
-import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.util.AbstractSolrTestCase;
-
-import junit.framework.TestCase;
+import org.apache.solr.util.ContentStream;
 
 public class SolrRequestParserTest extends AbstractSolrTestCase {
 
@@ -118,5 +110,21 @@
     parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
     assertEquals( 1, streams.size() );
     assertEquals( txt, IOUtils.toString( streams.get(0).getStream() ) );
+  }
+  
+  public void testUrlParamParsing()
+  {
+    String[][] teststr = new String[][] {
+      { "this is simple", "this%20is%20simple" },
+      { "this is simple", "this+is+simple" },
+      { "\u00FC", "%C3%BC" },   // lower-case "u" with diaeresis/umlaut
+      { "\u0026", "%26" },      // &
+      { "\u20AC", "%E2%82%AC" } // euro
+    };
+    
+    for( String[] tst : teststr ) {
+      MultiMapSolrParams params = SolrRequestParsers.parseQueryString( "val="+tst[1] );
+      assertEquals( tst[0], params.get( "val" ) );
+    }
   }
 }

Modified: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java?view=diff&rev=524524&r1=524523&r2=524524
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java (original)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java Sat Mar
31 20:43:42 2007
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.util.ArrayList;
@@ -178,17 +179,22 @@
   {
     Map<String,String[]> map = new HashMap<String, String[]>();
     if( queryString != null && queryString.length() > 0 ) {
-      for( String kv : queryString.split( "&" ) ) {
-        int idx = kv.indexOf( '=' );
-        if( idx > 0 ) {
-          String name = URLDecoder.decode( kv.substring( 0, idx ));
-          String value = URLDecoder.decode( kv.substring( idx+1 ));
-          MultiMapSolrParams.addParam( name, value, map );
-        }
-        else {
-          String name = URLDecoder.decode( kv );
-          MultiMapSolrParams.addParam( name, "", map );
+      try {
+        for( String kv : queryString.split( "&" ) ) {
+          int idx = kv.indexOf( '=' );
+          if( idx > 0 ) {
+            String name = URLDecoder.decode( kv.substring( 0, idx ), "UTF-8");
+            String value = URLDecoder.decode( kv.substring( idx+1 ), "UTF-8");
+            MultiMapSolrParams.addParam( name, value, map );
+          }
+          else {
+            String name = URLDecoder.decode( kv, "UTF-8" );
+            MultiMapSolrParams.addParam( name, "", map );
+          }
         }
+      }
+      catch( UnsupportedEncodingException uex ) {
+        throw new SolrException( 500, uex );
       }
     }
     return new MultiMapSolrParams( map );



Mime
View raw message