[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.24,1.25
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-10-27 00:57:44
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26105/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java RequestContextTest.java Log Message: bug #1051123 ServletUnit handling of parameter encoding was not cleaning up url-encodings Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- HttpServletRequestTest.java 23 Sep 2004 22:48:20 -0000 1.24 +++ HttpServletRequestTest.java 27 Oct 2004 00:57:33 -0000 1.25 @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.ByteArrayInputStream; import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -31,10 +32,7 @@ import javax.servlet.Servlet; import javax.servlet.ServletException; -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.PutMethodWebRequest; -import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.*; import junit.framework.Test; import junit.framework.TestSuite; @@ -166,6 +164,15 @@ } + public void testInlineParameterWithEmbeddedSpace() throws Exception { + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=dark+red&age=12" ); + HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), NO_MESSAGE_BODY ); + + assertEquals( "age parameter", "12", request.getParameter( "age" ) ); + assertEquals( "color parameter", "dark red", request.getParameter( "color" ) ); + } + + public void testInlineMultiValuedParameter() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" ); HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), NO_MESSAGE_BODY ); @@ -446,20 +453,36 @@ public void testSpecifiedCharEncoding() throws Exception { String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; - String paramString = "param1=red¶m2=" + hebrewValue; + String paramString = "param1=red¶m2=%E0%E1%E2%E3"; // use iso-8859-8 to encode the data WebRequest wr = new PostMethodWebRequest( "http://localhost/simple" ); wr.setHeaderField( "Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-8" ); - ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), paramString.getBytes( "ISO-8859-8" ) ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), paramString.getBytes( "iso-8859-1" ) ); assertEquals( "param1 value", "red", request.getParameter( "param1") ); assertEquals( "param2 value", hebrewValue, request.getParameter( "param2") ); } + public void ntestSpecifiedCharEncoding2() throws Exception { + String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; + HttpUnitOptions.setDefaultCharacterSet( "iso-8859-8" ); + WebRequest wr = new PostMethodWebRequest( "http://localhost/simple" ); + wr.setParameter( "param1", "red" ); + wr.setParameter( "param2", hebrewValue ); + wr.setHeaderField( "Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-8" ); + ServletUnitClient client = ServletUnitClient.newClient( null ); + ByteArrayOutputStream messageBody = client.getMessageBody( wr ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), messageBody.toByteArray() ); + String parameter = request.getParameter( "param2"); + assertEquals( "param2 value", hebrewValue, parameter ); + assertEquals( "param1 value", "red", request.getParameter( "param1") ); + } + + public void testSuppliedCharEncoding() throws Exception { String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; - String paramString = "param1=red¶m2=" + hebrewValue; + String paramString = "param1=red¶m2=%E0%E1%E2%E3"; // use iso-8859-8 to encode the data, then string is URL encoded WebRequest wr = new PostMethodWebRequest( "http://localhost/simple" ); - ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), paramString.getBytes( "ISO-8859-8" ) ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), paramString.getBytes( "ISO-8859-1" ) ); request.setCharacterEncoding( "ISO-8859-8" ); assertEquals( "param1 value", "red", request.getParameter( "param1") ); assertEquals( "param2 value", hebrewValue, request.getParameter( "param2") ); Index: RequestContextTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/RequestContextTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RequestContextTest.java 2 Mar 2004 10:54:15 -0000 1.3 +++ RequestContextTest.java 27 Oct 2004 00:57:34 -0000 1.4 @@ -103,8 +103,8 @@ public void testEncodedParameterParsing() throws Exception { RequestContext rc = new RequestContext( new URL( "http://localhost/basic" )); String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; - String paramString = "param=red¶m1=" + hebrewValue + "¶m=blue"; - rc.setMessageBody( paramString.getBytes( "iso-8859-8" ) ); + String paramString = "param=red¶m1=%E0%E1%E2%E3¶m=blue"; + rc.setMessageBody( paramString.getBytes( "iso-8859-1" ) ); rc.setMessageEncoding( "iso-8859-8" ); assertMatchingSet( "parameter names", new String[] { "param", "param1" }, rc.getParameterNames() ); assertMatchingSet( "param values", new String[] { "red", "blue" }, rc.getParameterValues( "param" ) ); |