mirror of https://github.com/apache/lucene.git
fix queryString parsing to handle UTF8 (percent encoded): SOLR-202
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@524524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6b58a8536b
commit
55ee8f2305
|
@ -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.HashMap;
|
|||
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 {
|
||||
|
||||
|
@ -119,4 +111,20 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {
|
|||
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" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.File;
|
|||
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,18 +179,23 @@ public class SolrRequestParsers
|
|||
{
|
||||
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue