Apache Lucene open-source search software
fixing a request parsing bug. When posting "application/x-www-form-urlencoded" and including a charset, application/x-www-form-urlencoded; charset=utf-8, the parser would treat the body as raw content.
Ryan McKinleyd75a031c5e1f
diff --git a/build.xml b/build.xmlindex 4b87210a1f3..e06e4120451 100644--- a/build.xml+++ b/build.xml@@ -380,6 +380,7 @@manifest="${dest}/META-INF/MANIFEST.MF"><lib dir="${lib}"><exclude name="servlet-api*.jar" />+ <exclude name="easymock.jar" /></lib><lib dir="${dist}"><include name="${fullnamever}.jar" />@@ -479,3 +480,4 @@</project>+diff --git a/lib/easymock.jar b/lib/easymock.jarnew file mode 100644index 00000000000..9936e77e57c--- /dev/null+++ b/lib/easymock.jar@@ -0,0 +1,2 @@+AnyObjectId[c4159f5a0a4c19d6afc89cbc271208acb8ba7dff] was removed in git history.+Apache SVN contains full history.\ No newline at end of filediff --git a/src/test/org/apache/solr/servlet/SolrRequestParserTest.java b/src/test/org/apache/solr/servlet/SolrRequestParserTest.javaindex 99c12616573..d6fe9fc4e0e 100644--- a/src/test/org/apache/solr/servlet/SolrRequestParserTest.java+++ b/src/test/org/apache/solr/servlet/SolrRequestParserTest.java@@ -17,6 +17,10 @@package org.apache.solr.servlet;+import static org.easymock.EasyMock.createMock;+import static org.easymock.EasyMock.expect;+import static org.easymock.EasyMock.replay;+import java.net.URL;import java.util.ArrayList;import java.util.Collections;@@ -24,6 +28,8 @@ import java.util.HashMap;import java.util.List;import java.util.Map;+import javax.servlet.http.HttpServletRequest;+import org.apache.commons.io.IOUtils;import org.apache.solr.core.SolrConfig;import org.apache.solr.core.SolrCore;@@ -127,4 +133,35 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {assertEquals( tst[0], params.get( "val" ) );}}++ public void testStandardParseParamsAndFillStreams() throws Exception+ {+ ArrayList<ContentStream> streams = new ArrayList<ContentStream>();+ Map<String,String[]> params = new HashMap<String, String[]>();+ params.put( "q", new String[] { "hello" } );++ // Set up the expected behavior+ String[] ct = new String[] {+ "application/x-www-form-urlencoded",+ "Application/x-www-form-urlencoded",+ "application/x-www-form-urlencoded; charset=utf-8",+ "application/x-www-form-urlencoded;"+ };++ for( String contentType : ct ) {+ HttpServletRequest request = createMock(HttpServletRequest.class);+ expect(request.getMethod()).andReturn("POST").anyTimes();+ expect(request.getContentType()).andReturn( contentType ).anyTimes();+ expect(request.getParameterMap()).andReturn(params).anyTimes();+ replay(request);++ MultipartRequestParser multipart = new MultipartRequestParser( 1000000 );+ RawRequestParser raw = new RawRequestParser();+ StandardRequestParser standard = new StandardRequestParser( multipart, raw );++ SolrParams p = standard.parseParamsAndFillStreams( request, streams );++ assertEquals( "contentType: "+contentType, "hello", p.get("q") );+ }+ }}diff --git a/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java b/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.javaindex 6f1995b2d41..25d7816c50f 100644--- a/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java+++ b/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java@@ -367,6 +367,10 @@ class StandardRequestParser implements SolrRequestParserif( "POST".equals( method ) ) {String contentType = req.getContentType();if( contentType != null ) {+ int idx = contentType.indexOf( ';' );+ if( idx > 0 ) { // remove the charset definition "; charset=utf-8"+ contentType = contentType.substring( 0, idx );+ }if( "application/x-www-form-urlencoded".equals( contentType.toLowerCase() ) ) {return new ServletSolrParams(req); // just get the params from parameterMap}@@ -385,3 +389,4 @@ class StandardRequestParser implements SolrRequestParser+