From: <no...@us...> - 2003-06-28 17:24:31
|
Log Message: ----------- Fix for bug 738548 - "Form values are not Posted Properly to Server" Modified Files: -------------- /cvsroot/htmlunit/htmlunit/src/xdocs: changes.xml /cvsroot/htmlunit/htmlunit/src/test/java/com/gargoylesoftware/htmlunit: SanityCheck.java /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit: HttpWebConnection.java Revision Data ------------- Index: SanityCheck.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SanityCheck.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SanityCheck.java 10 Jun 2003 11:57:00 -0000 1.4 +++ SanityCheck.java 28 Jun 2003 17:24:27 -0000 1.5 @@ -236,6 +236,30 @@ * correctly for POST methods. * @throws Exception If something goes wrong. */ + public void testPostMethodWithDuplicateParameters() throws Exception { + final WebClient webClient = new WebClient(); + final HtmlPage firstPage = (HtmlPage)webClient.getPage(getPrintEnvUrl()); + + assertEquals("GET", firstPage.getHtmlElementById("REQUEST_METHOD").asText()); + + final HtmlForm form = firstPage.getFormByName("form1"); + form.setMethodAttribute("post"); + + final HtmlSubmitInput button = (HtmlSubmitInput)form.getInputByName("button1"); + button.getElement().setAttribute("name", "textfield1"); + + final HtmlPage secondPage = (HtmlPage)button.click(); + assertEquals("POST", secondPage.getHtmlElementById("REQUEST_METHOD").asText()); + assertEquals("", secondPage.getHtmlElementById("QUERY_STRING").asText()); + assertEquals("textfield1=*&textfield1=PushMe", + secondPage.getHtmlElementById("CONTENT").asText()); + } + + /** + * Test against htmlunit.sourceforge.net to make sure parameters are being passed + * correctly for POST methods. + * @throws Exception If something goes wrong. + */ public void testPostMethodWithParameters() throws Exception { final WebClient webClient = new WebClient(); final HtmlPage firstPage = (HtmlPage)webClient.getPage(getPrintEnvUrl()); Index: changes.xml =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/xdocs/changes.xml,v retrieving revision 1.111 retrieving revision 1.112 diff -u -d -r1.111 -r1.112 --- changes.xml 26 Jun 2003 12:07:01 -0000 1.111 +++ changes.xml 28 Jun 2003 17:24:27 -0000 1.112 @@ -124,6 +124,9 @@ Changed HtmlTextArea.setText() to actually modify the DOM Patch provided by Barnaby Court. </action> + <action type="update" dev="mbowler" id="738548 "> + Fix for bug 738548 - "Form values are not Posted Properly to Server" + </action> </release> </body> Index: HttpWebConnection.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- HttpWebConnection.java 10 Jun 2003 11:56:55 -0000 1.10 +++ HttpWebConnection.java 28 Jun 2003 17:24:28 -0000 1.11 @@ -229,10 +229,19 @@ if( queryString != null ) { httpMethod.setQueryString(queryString); } - final Iterator iterator = parameters.iterator(); + Iterator iterator; + + // Note that this has to be done in two loops otherwise it won't + // be able to support two elements with the same name. + iterator = parameters.iterator(); while( iterator.hasNext() ) { final NameValuePair pair = ( NameValuePair )iterator.next(); ( ( PostMethod )httpMethod ).removeParameter( pair.getName(), pair.getValue() ); + } + + iterator = parameters.iterator(); + while( iterator.hasNext() ) { + final NameValuePair pair = ( NameValuePair )iterator.next(); ( ( PostMethod )httpMethod ).addParameter( pair.getName(), pair.getValue() ); } } |