[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-develop
Subject:    [HtmlUnit] SF.net SVN: htmlunit:[5014] trunk/htmlunit/src
From:       mguillem () users ! sourceforge ! net
Date:       2009-09-25 19:51:16
Message-ID: E1MrGp2-0007l9-KD () d5vjzd1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 5014
          http://htmlunit.svn.sourceforge.net/htmlunit/?rev=5014&view=rev
Author:   mguillem
Date:     2009-09-25 19:51:16 +0000 (Fri, 25 Sep 2009)

Log Message:
-----------
- FormEncodingType.getInstance returns URL_ENCODED if the requested encoding type \
                doesn't exist.
- Form submission: don't send a Content-Type header when method is GET.

Issue 2860721

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/FormEncodingType.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java


Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml	2009-09-25 18:46:14 UTC (rev 5013)
+++ trunk/htmlunit/src/changes/changes.xml	2009-09-25 19:51:16 UTC (rev 5014)
@@ -6,6 +6,12 @@
 
     <body>
         <release version="2.7" date="?" description="Bugfixes, (initial)??? IE8 \
support"> +            <action type="fix" dev="mguillem">
+                Form submission: don't send a Content-Type header when method is \
GET. +            </action>
+            <action type="fix" dev="mguillem" issue="2860721">
+                FormEncodingType.getInstance returns URL_ENCODED if the requested \
encoding type doesn't exist. +            </action>
             <action type="fix" dev="mguillem" issue="2819477">
                 JavaScript: don't call (i)frame's onload handler for the dummy page \
that fill the frame until the real content is loaded.  </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/FormEncodingType.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/FormEncodingType.java	2009-09-25 \
                18:46:14 UTC (rev 5013)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/FormEncodingType.java	2009-09-25 \
19:51:16 UTC (rev 5014) @@ -54,23 +54,16 @@
      * Returns the constant that matches the specified name.
      *
      * @param name the name to search by
-     * @return the constant that matches the specified name
+     * @return the constant corresponding to the specified name, {@link \
                #URL_ENCODED} if none match.
      */
     public static FormEncodingType getInstance(final String name) {
         final String lowerCaseName = name.toLowerCase();
 
-        for (final FormEncodingType type : new FormEncodingType[] {URL_ENCODED, \
                MULTIPART}) {
-            if (type.getName().equals(lowerCaseName)) {
-                return type;
-            }
+        if (MULTIPART.getName().equals(lowerCaseName)) {
+            return MULTIPART;
         }
 
-        // Special case: empty string defaults to URL encoded
-        if (name.equals("")) {
-            return URL_ENCODED;
-        }
-
-        throw new IllegalArgumentException("No encoding type found for [" + name + \
"]"); +        return URL_ENCODED;
     }
 
     /**

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java	2009-09-25 \
                18:46:14 UTC (rev 5013)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java	2009-09-25 \
19:51:16 UTC (rev 5014) @@ -194,7 +194,9 @@
 
         final WebRequestSettings settings = new WebRequestSettings(url, method);
         settings.setRequestParameters(parameters);
-        settings.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
 +        if (HttpMethod.POST == method) {
+            settings.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
 +        }
         settings.setCharset(getSubmitCharset());
         settings.setAdditionalHeader("Referer", \
                htmlPage.getWebResponse().getRequestSettings().getUrl()
                 .toExternalForm());

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java	2009-09-25 \
                18:46:14 UTC (rev 5013)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java	2009-09-25 \
19:51:16 UTC (rev 5014) @@ -20,6 +20,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -1323,4 +1324,53 @@
         setExpectedAlerts("foo1");
         assertEquals(getExpectedAlerts(), getCollectedAlerts(driver));
     }
+
+    /**
+     * Verify Content-Type header sent with form submission.
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void enctype() throws Exception {
+        enctypeTest("", "post", "application/x-www-form-urlencoded");
+        enctypeTest("application/x-www-form-urlencoded", "post", \
"application/x-www-form-urlencoded"); +        enctypeTest("multipart/form-data", \
"post", "multipart/form-data"); +
+        // for GET, no Content-Type header should be sent
+        enctypeTest("", "get", null);
+        enctypeTest("application/x-www-form-urlencoded", "get", null);
+        enctypeTest("multipart/form-data", "get", null);
+    }
+
+    /**
+     * Regression test for bug
+     * <a href="http://sf.net/suppor/tracker.php?aid=2860721">2860721</a>: incorrect \
enctype form attribute +     * should be ignored.
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void enctype_incorrect() throws Exception {
+        enctypeTest("text/html", "post", "application/x-www-form-urlencoded");
+        enctypeTest("text/html", "get", null);
+    }
+
+    private void enctypeTest(final String enctype, final String method, final String \
expectedCntType) throws Exception { +        final String html = \
"<html><head><script>" +            + "function test() {"
+            + "  var f = document.forms[0];"
+            + "  f.submit();"
+            + "}"
+            + "</script></head><body onload='test()'>"
+            + "<form action='foo.html' enctype='" + enctype + "' method='" + method \
+ "'>" +            + "  <input name='myField' value='some value'>"
+            + "</form></body></html>";
+
+        getMockWebConnection().setDefaultResponse("");
+        loadPageWithAlerts2(html);
+        String headerValue = \
getMockWebConnection().getLastWebRequestSettings().getAdditionalHeaders() +           \
.get("Content-Type"); +        // Can't test equality for multipart/form-data as it \
will have the form: +        // multipart/form-data; \
boundary=---------------------------42937861433140731107235900 +        headerValue = \
StringUtils.substringBefore(headerValue, ";"); +        assertEquals(expectedCntType, \
headerValue); +    }
 }


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic