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.

This includes tests to repeat the error.

It also adds easymock.jar to lib, and excludes it from distribution.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@535548 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-05-05 17:14:22 +00:00
parent 3fb29c4bd9
commit d75a031c5e
4 changed files with 46 additions and 0 deletions

View File

@ -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>

2
lib/easymock.jar Normal file
View File

@ -0,0 +1,2 @@
AnyObjectId[c4159f5a0a4c19d6afc89cbc271208acb8ba7dff] was removed in git history.
Apache SVN contains full history.

View File

@ -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") );
}
}
}

View File

@ -367,6 +367,10 @@ class StandardRequestParser implements SolrRequestParser
if( "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