353267 Request._parameters initialization bug

This commit is contained in:
Jan Bartel 2011-09-19 19:05:49 +10:00
parent c984d25871
commit 479d9606ec
2 changed files with 120 additions and 69 deletions

View File

@ -186,7 +186,7 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* Extract Paramters from query string and/or form _content.
* Extract Parameters from query string and/or form _content.
*/
public void extractParameters()
{
@ -202,6 +202,8 @@ public class Request implements HttpServletRequest
_paramsExtracted = true;
try
{
// Handle query string
if (_uri!=null && _uri.hasQuery())
{
@ -285,6 +287,13 @@ public class Request implements HttpServletRequest
}
}
}
finally
{
//ensure params always set (even if empty) after extraction
if (_parameters==null)
_parameters=_baseParameters;
}
}
/* ------------------------------------------------------------ */
public AsyncContext getAsyncContext()

View File

@ -24,12 +24,15 @@ import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.Assert;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
@ -69,6 +72,45 @@ public class RequestTest
_server.join();
}
@Test
public void testParamExtraction() throws Exception
{
_handler._checker = new RequestTester()
{
public boolean check(HttpServletRequest request,HttpServletResponse response)
{
Map map = null;
try
{
//do the parse
request.getParameterMap();
Assert.fail("Expected parsing failure");
return false;
}
catch (Exception e)
{
//catch the error and check the param map is not null
map = request.getParameterMap();
assertFalse(map == null);
assertTrue(map.isEmpty());
}
return true;
}
};
//Send a request with query string with illegal hex code to cause
//an exception parsing the params
String request="GET /?param=%ZZaaa HTTP/1.1\r\n"+
"Host: whatever\r\n"+
"Content-Type: text/html;charset=utf8\n"+
"\n";
String response = _connector.getResponses(request);
}
@Test
public void testContentTypeEncoding() throws Exception
{