[HtmlUnit] SVN: [15487] trunk/htmlunit/src
rbri--- via HtmlUnit-develop <[email protected]> Wed, 18 Jul 2018 19:33:00 +0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Revision: 15487
http://sourceforge.net/p/htmlunit/code/15487
Author: rbri
Date: 2018-07-18 19:32:57 +0000 (Wed, 18 Jul 2018)
Log Message:
-----------
next step in our endless encoding fight - fix iframe and frameset url encoding
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java
trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java
trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-07-18 07:39:43 UTC (rev 15486)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-07-18 19:32:57 UTC (rev 15487)
@@ -179,6 +179,7 @@
}
try {
final WebRequest request = new WebRequest(url);
+ request.setCharset(getPage().getCharset());
request.setAdditionalHeader(HttpHeader.REFERER, getPage().getUrl().toExternalForm());
getPage().getEnclosingWindow().getWebClient().getPage(enclosedWindow_, request);
}
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 07:39:43 UTC (rev 15486)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 19:32:57 UTC (rev 15487)
@@ -97,7 +97,9 @@
final String response;
if (requestString.contains("/favicon.ico")) {
response = "HTTP/1.1 404 Not Found\r\n"
- + "Content-Length: 0\r\n\r\n";
+ + "Content-Length: 0\r\n"
+ + "Connection: close\r\n"
+ + "\r\n";
}
else {
requests_.add(requestString);
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:39:43 UTC (rev 15486)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 19:32:57 UTC (rev 15487)
@@ -18,7 +18,6 @@
import java.net.URL;
import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
import org.junit.After;
import org.junit.Test;
@@ -164,104 +163,58 @@
IE = "/test.html?k\u00c3\u00b6nig")
@NotYetImplemented(IE)
public void anchorUrlEncodingUTF8Header() throws Exception {
- urlEncoding(true, "UTF-8");
+ anchorUrlEncoding(true, "UTF-8");
}
-//
-// /**
-// * @throws Exception if the test fails
-// */
-// @Test
-// @Alerts(DEFAULT = "/test.html?k%C3%B6nig",
-// IE = "/test.html?k\u00c3\u00b6nig")
-// @NotYetImplemented(IE)
-// public void anchorUrlEncodingUTF8Meta() throws Exception {
-// urlEncoding(false, "UTF-8");
-// }
-//
-// /**
-// * @throws Exception if the test fails
-// */
-// @Test
-// @Alerts(DEFAULT = "/test.html?k%F6nig",
-// IE = "/test.html?k\u00f6nig")
-// @NotYetImplemented(IE)
-// public void anchorUrlEncodingISO8859_1Header() throws Exception {
-// urlEncoding(true, "ISO-8859-1");
-// }
-//
-// /**
-// * @throws Exception if the test fails
-// */
-// @Test
-// @Alerts(DEFAULT = "/test.html?k%F6nig",
-// IE = "/test.html?k\u00f6nig")
-// @NotYetImplemented(IE)
-// public void anchorUrlEncodingISO8859_1Meta() throws Exception {
-// urlEncoding(false, "ISO-8859-1");
-// }
-//
-// /**
-// * @throws Exception if the test fails
-// */
-// @Test
-// @Alerts("/test.html?k?nig")
-// public void anchorUrlEncodingWindows_1251Header() throws Exception {
-// urlEncoding(true, "Windows-1251");
-// }
-// /**
-// * @throws Exception if the test fails
-// */
-// @Test
-// @Alerts("/test.html?k?nig")
-// public void anchorUrlEncodingWindows_1251Meta() throws Exception {
-// urlEncoding(false, "Windows-1251");
-// }
- private void urlEncoding(final boolean header, final String charset) throws Exception {
- String html = "<html>\n"
- + "<head><title>foo</title>\n";
- if (!header) {
- html += " <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n";
- }
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%C3%B6nig",
+ IE = "/test.html?k\u00c3\u00b6nig")
+ @NotYetImplemented(IE)
+ public void anchorUrlEncodingUTF8Meta() throws Exception {
+ anchorUrlEncoding(false, "UTF-8");
+ }
- html += "</head>\n"
- + "<body>\n"
- + " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>\n"
- + "</body></html>";
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%F6nig",
+ IE = "/test.html?k\u00f6nig")
+ @NotYetImplemented(IE)
+ public void anchorUrlEncodingISO8859_1Header() throws Exception {
+ anchorUrlEncoding(true, "ISO-8859-1");
+ }
- String firstResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + html.length() + "\r\n"
- + "Content-Type: text/html";
- if (header) {
- firstResponse += "; charset=" + charset;
- }
- firstResponse += "\r\n"
- + "Connection: close\r\n"
- + "\r\n" + html;
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%F6nig",
+ IE = "/test.html?k\u00f6nig")
+ @NotYetImplemented(IE)
+ public void anchorUrlEncodingISO8859_1Meta() throws Exception {
+ anchorUrlEncoding(false, "ISO-8859-1");
+ }
- final String html2 = "<html><head></head><body>"
- + "</body></html>";
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts("/test.html?k?nig")
+ public void anchorUrlEncodingWindows_1251Header() throws Exception {
+ anchorUrlEncoding(true, "Windows-1251");
+ }
- final String secondResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + html2.length() + "\r\n"
- + "Content-Type: text/html; charset=" + charset + "\r\n"
- + "Connection: close\r\n"
- + "\r\n"
- + html2;
-
- primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
- primitiveWebServer_.setCharset(Charset.forName(charset));
- primitiveWebServer_.start();
-
- final WebDriver driver = getWebDriver();
-
- driver.get(URL_FIRST.toString());
- driver.findElement(By.id("myLink")).click();
-
- String reqUrl = primitiveWebServer_.getRequests().get(1);
- reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);
-
- assertEquals(getExpectedAlerts()[0], reqUrl);
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts("/test.html?k?nig")
+ public void anchorUrlEncodingWindows_1251Meta() throws Exception {
+ anchorUrlEncoding(false, "Windows-1251");
}
/**
@@ -272,41 +225,7 @@
IE = "/test.css?k\u00c3\u00b6nig")
@NotYetImplemented(IE)
public void linkUrlEncodingUTF8Header() throws Exception {
- final String html = "<html>\n"
- + "<head><title>foo</title>\n"
- + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>"
- + "</head>\n"
- + "<body>\n"
- + "</body></html>";
-
- final String firstResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + html.length() + "\r\n"
- + "Content-Type: text/html; charset=UTF-8\r\n"
- + "Connection: close\r\n"
- + "\r\n"
- + html;
-
- final String css = "p { color: red; }";
-
- final String secondResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + css.length() + "\r\n"
- + "Content-Type: text/css\r\n"
- + "Connection: close\r\n"
- + "\r\n"
- + css;
-
- primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
- primitiveWebServer_.setCharset(StandardCharsets.UTF_8);
- primitiveWebServer_.start();
-
- final WebDriver driver = getWebDriver();
-
- driver.get(URL_FIRST.toString());
-
- String reqUrl = primitiveWebServer_.getRequests().get(1);
- reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);
-
- assertEquals(getExpectedAlerts()[0], reqUrl);
+ linkUrlEncoding(true, "UTF-8");
}
/**
@@ -317,42 +236,51 @@
IE = "/test.css?k\u00c3\u00b6nig")
@NotYetImplemented(IE)
public void linkUrlEncodingUTF8Meta() throws Exception {
- final String html = "<html>\n"
- + "<head><title>foo</title>\n"
- + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"
- + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>"
- + "</head>\n"
- + "<body>\n"
- + "</body></html>";
+ linkUrlEncoding(false, "UTF-8");
+ }
- final String firstResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + html.length() + "\r\n"
- + "Content-Type: text/html\r\n"
- + "Connection: close\r\n"
- + "\r\n"
- + html;
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.css?k%F6nig",
+ IE = "/test.css?k\u00f6nig")
+ @NotYetImplemented(IE)
+ public void linkUrlEncodingISO8859_1Header() throws Exception {
+ linkUrlEncoding(true, "ISO_8859_1");
+ }
- final String css = "p { color: red; }";
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.css?k%F6nig",
+ IE = "/test.css?k\u00f6nig")
+ @NotYetImplemented(IE)
+ public void linkUrlEncodingISO8859_1Meta() throws Exception {
+ linkUrlEncoding(false, "ISO_8859_1");
+ }
- final String secondResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + css.length() + "\r\n"
- + "Content-Type: text/css\r\n"
- + "Connection: close\r\n"
- + "\r\n"
- + css;
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%C3%B6nig",
+ IE = "/test.html?k\u00c3\u00b6nig")
+ @NotYetImplemented(IE)
+ public void iframeUrlEncodingUTF8Header() throws Exception {
+ iframeUrlEncoding(true, "UTF-8");
+ }
- primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
- primitiveWebServer_.setCharset(StandardCharsets.UTF_8);
- primitiveWebServer_.start();
-
- final WebDriver driver = getWebDriver();
-
- driver.get(URL_FIRST.toString());
-
- String reqUrl = primitiveWebServer_.getRequests().get(1);
- reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);
-
- assertEquals(getExpectedAlerts()[0], reqUrl);
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%C3%B6nig",
+ IE = "/test.html?k\u00c3\u00b6nig")
+ @NotYetImplemented(IE)
+ public void iframeUrlEncodingUTF8Meta() throws Exception {
+ iframeUrlEncoding(false, "UTF-8");
}
/**
@@ -359,40 +287,77 @@
* @throws Exception if the test fails
*/
@Test
- @Alerts(DEFAULT = "/test.css?k%F6nig",
- IE = "/test.css?k\u00f6nig")
+ @Alerts(DEFAULT = "/test.html?k%F6nig",
+ IE = "/test.html?k\u00f6nig")
@NotYetImplemented(IE)
- public void linkUrlEncodingISO8859_1Header() throws Exception {
- final String html = "<html>\n"
- + "<head><title>foo</title>\n"
- + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>"
- + "</head>\n"
+ public void iframeUrlEncodingISO8859_1Header() throws Exception {
+ framesetUrlEncoding("ISO_8859_1");
+ }
+
+ private void anchorUrlEncoding(final boolean header, final String charset) throws Exception {
+ urlEncoding(header, charset,
+ null,
+ " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>",
+ true);
+ }
+
+ private void linkUrlEncoding(final boolean header, final String charset) throws Exception {
+ urlEncoding(header, charset,
+ " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>",
+ "",
+ false);
+ }
+
+ private void iframeUrlEncoding(final boolean header, final String charset) throws Exception {
+ urlEncoding(header, charset,
+ " <iframe src='test.html?k\u00F6nig'></iframe> ",
+ "",
+ false);
+ }
+
+ private void urlEncoding(final boolean header, final String charset,
+ final String addHeader,
+ final String addHtml,
+ final boolean click) throws Exception {
+ String html = "<html>\n"
+ + "<head><title>foo</title>\n";
+ if (!header) {
+ html += " <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n";
+ }
+ if (addHeader != null) {
+ html += addHeader + "\n";
+ }
+
+ html += "</head>\n"
+ "<body>\n"
+ + addHtml + "\n"
+ "</body></html>";
- final String firstResponse = "HTTP/1.1 200 OK\r\n"
+ String firstResponse = "HTTP/1.1 200 OK\r\n"
+ "Content-Length: " + html.length() + "\r\n"
- + "Content-Type: text/html; charset=ISO-8859-1\r\n"
+ + "Content-Type: text/html";
+ if (header) {
+ firstResponse += "; charset=" + charset;
+ }
+ firstResponse += "\r\n"
+ "Connection: close\r\n"
- + "\r\n"
- + html;
+ + "\r\n" + html;
- final String css = "p { color: red; }";
-
- final String secondResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + css.length() + "\r\n"
- + "Content-Type: text/css\r\n"
+ final String secondResponse = "HTTP/1.1 404 Not Found\r\n"
+ + "Content-Length: 0\r\n"
+ "Connection: close\r\n"
- + "\r\n"
- + css;
+ + "\r\n";
primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
- primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1);
+ primitiveWebServer_.setCharset(Charset.forName(charset));
primitiveWebServer_.start();
final WebDriver driver = getWebDriver();
driver.get(URL_FIRST.toString());
+ if (click) {
+ driver.findElement(By.id("myLink")).click();
+ }
String reqUrl = primitiveWebServer_.getRequests().get(1);
reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);
@@ -404,36 +369,42 @@
* @throws Exception if the test fails
*/
@Test
- @Alerts(DEFAULT = "/test.css?k%F6nig",
- IE = "/test.css?k\u00f6nig")
+ @Alerts(DEFAULT = "/test.html?k%C3%B6nig",
+ IE = "/test.html?k\u00c3\u00b6nig")
@NotYetImplemented(IE)
- public void linkUrlEncodingISO8859_1Meta() throws Exception {
+ public void framesetUrlEncodingUTF8() throws Exception {
+ framesetUrlEncoding("UTF-8");
+ }
+
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts(DEFAULT = "/test.html?k%F6nig",
+ IE = "/test.html?k\u00f6nig")
+ @NotYetImplemented(IE)
+ public void framesetUrlEncodingISO8859_1() throws Exception {
+ framesetUrlEncoding("ISO_8859_1");
+ }
+
+ private void framesetUrlEncoding(final String charset) throws Exception {
final String html = "<html>\n"
- + "<head><title>foo</title>\n"
- + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n"
- + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>"
- + "</head>\n"
- + "<body>\n"
- + "</body></html>";
+ + "<frameset><frame src='test.html?k\u00F6nig'></frameset>\n"
+ + "</html>";
final String firstResponse = "HTTP/1.1 200 OK\r\n"
+ "Content-Length: " + html.length() + "\r\n"
- + "Content-Type: text/html\r\n"
+ + "Content-Type: text/html; charset=" + charset + "\r\n"
+ "Connection: close\r\n"
- + "\r\n"
- + html;
+ + "\r\n" + html;
- final String css = "p { color: red; }";
-
- final String secondResponse = "HTTP/1.1 200 OK\r\n"
- + "Content-Length: " + css.length() + "\r\n"
- + "Content-Type: text/css\r\n"
+ final String secondResponse = "HTTP/1.1 404 Not Found\r\n"
+ + "Content-Length: 0\r\n"
+ "Connection: close\r\n"
- + "\r\n"
- + css;
+ + "\r\n";
primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
- primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1);
+ primitiveWebServer_.setCharset(Charset.forName(charset));
primitiveWebServer_.start();
final WebDriver driver = getWebDriver();
@@ -446,7 +417,6 @@
assertEquals(getExpectedAlerts()[0], reqUrl);
}
-// BaseFrameElement.java (2 matches)
// HtmlApplet.java
// HtmlArea.java
// HtmlEmbed.java
@@ -454,4 +424,5 @@
// HtmlImage.java
// HtmlImageInput.java
// HtmlObject.java
+
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot