<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201850] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201850">201850</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2016-06-08 22:07:24 -0700 (Wed, 08 Jun 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Perform IDNA encoding on parameters for setHostAndPort and setHost
https://bugs.webkit.org/show_bug.cgi?id=158371
<rdar://problem/16869342>
Patch by John Wilander <wilander@apple.com> on 2016-06-08
Reviewed by Brent Fulgham.
Source/WebCore:
Tests: fast/dom/set-document-location-host-to-unaccepted-values.html
fast/dom/set-document-location-hostname-to-unaccepted-values.html
http/tests/dom/set-document-location-host-to-accepted-values.html
http/tests/dom/set-document-location-hostname-to-accepted-values.html
* platform/URL.cpp:
(WebCore::containsOnlyASCII):
Moved up to enable usage in URL::setHost and URL::setHostAndPort.
(WebCore::appendEncodedHostname):
Moved up to enable usage in URL::setHost and URL::setHostAndPort.
(WebCore::URL::setHost):
Now disallows the colon character, does IDNA encoding, and uses StringBuilder.
(WebCore::URL::setHostAndPort):
Now disallows multiple colons, disallows non-numeric ports, disallows the empty
string, does IDNA encoding, and uses StringBuilder.
LayoutTests:
* fast/dom/resources/set-document-location-iframe.html: Added.
* fast/dom/set-document-location-host-to-unaccepted-values-expected.txt: Added.
* fast/dom/set-document-location-host-to-unaccepted-values.html: Added.
* fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt: Added.
* fast/dom/set-document-location-hostname-to-unaccepted-values.html: Added.
* http/tests/dom/resources/set-document-location-iframe.html: Added.
* http/tests/dom/set-document-location-host-to-accepted-values-expected.txt: Added.
* http/tests/dom/set-document-location-host-to-accepted-values.html: Added.
* http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt: Added.
* http/tests/dom/set-document-location-hostname-to-accepted-values.html: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformURLcpp">trunk/Source/WebCore/platform/URL.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomresourcessetdocumentlocationiframehtml">trunk/LayoutTests/fast/dom/resources/set-document-location-iframe.html</a></li>
<li><a href="#trunkLayoutTestsfastdomsetdocumentlocationhosttounacceptedvaluesexpectedtxt">trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomsetdocumentlocationhosttounacceptedvalueshtml">trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values.html</a></li>
<li><a href="#trunkLayoutTestsfastdomsetdocumentlocationhostnametounacceptedvaluesexpectedtxt">trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomsetdocumentlocationhostnametounacceptedvalueshtml">trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values.html</a></li>
<li><a href="#trunkLayoutTestshttptestsdomresourcessetdocumentlocationiframehtml">trunk/LayoutTests/http/tests/dom/resources/set-document-location-iframe.html</a></li>
<li><a href="#trunkLayoutTestshttptestsdomsetdocumentlocationhosttoacceptedvaluesexpectedtxt">trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsdomsetdocumentlocationhosttoacceptedvalueshtml">trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values.html</a></li>
<li><a href="#trunkLayoutTestshttptestsdomsetdocumentlocationhostnametoacceptedvaluesexpectedtxt">trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsdomsetdocumentlocationhostnametoacceptedvalueshtml">trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (201849 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-06-09 02:41:01 UTC (rev 201849)
+++ trunk/LayoutTests/ChangeLog        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-06-08 John Wilander <wilander@apple.com>
+
+ Perform IDNA encoding on parameters for setHostAndPort and setHost
+ https://bugs.webkit.org/show_bug.cgi?id=158371
+ <rdar://problem/16869342>
+
+ Reviewed by Brent Fulgham.
+
+ * fast/dom/resources/set-document-location-iframe.html: Added.
+ * fast/dom/set-document-location-host-to-unaccepted-values-expected.txt: Added.
+ * fast/dom/set-document-location-host-to-unaccepted-values.html: Added.
+ * fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt: Added.
+ * fast/dom/set-document-location-hostname-to-unaccepted-values.html: Added.
+ * http/tests/dom/resources/set-document-location-iframe.html: Added.
+ * http/tests/dom/set-document-location-host-to-accepted-values-expected.txt: Added.
+ * http/tests/dom/set-document-location-host-to-accepted-values.html: Added.
+ * http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt: Added.
+ * http/tests/dom/set-document-location-hostname-to-accepted-values.html: Added.
+
</ins><span class="cx"> 2016-06-08 Ryan Haddad <ryanhaddad@apple.com>
</span><span class="cx">
</span><span class="cx"> Rebaseline js/dom/global-constructors-attributes.html for Mac after r201810
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomresourcessetdocumentlocationiframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/resources/set-document-location-iframe.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/resources/set-document-location-iframe.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/resources/set-document-location-iframe.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Dummy document to load before document.location test cases</title>
+</head>
+<body>
+<p id="status">
+ Before
+</p>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomsetdocumentlocationhosttounacceptedvaluesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values-expected.txt (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values-expected.txt        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+PASS: 'icl' + '\uf877' + 'oud.com' was not accepted.
+PASS: icloud.com:-1 was not accepted.
+PASS: icloud.com:11c was not accepted.
+PASS: icloud.com:11 was not accepted.
+PASS: icloud.com:80: was not accepted.
+PASS: icloud.com:80:80 was not accepted.
+PASS: icloud.com: was not accepted.
+PASS: :80 was not accepted.
+PASS: : was not accepted.
+PASS: empty string was not accepted.
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomsetdocumentlocationhosttounacceptedvalueshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/set-document-location-host-to-unaccepted-values.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,77 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Test for setting document.location.host to unaccepted values</title>
+</head>
+<body>
+<pre id="pre"></pre>
+<script>
+ // This function will be redefined as the test cases get executed
+ var testCaseOnload = function() {
+ runOneTestThatShouldNotBeAccepted(0);
+ };
+
+ var iframeDocument;
+ function iframeOnload() {
+ iframeDocument = document.getElementById("targetFrame").contentDocument;
+ testCaseOnload();
+ }
+
+ function log(s) {
+ document.getElementById("pre").appendChild(document.createTextNode(s));
+ }
+
+ function runOneTestThatShouldNotBeAccepted(testIndex) {
+ var testCasesThatShouldNotBeAccepted = [
+ { hostString : 'icl' + '\uf877' + 'oud.com', description : "'icl' + '\\uf877' + 'oud.com'" }
+ ,{ hostString : 'icloud.com:-1', description : false }
+ ,{ hostString : 'icloud.com:11c', description : false }
+ ,{ hostString : 'icloud.com:11', description : false }
+ ,{ hostString : 'icloud.com:80:', description : false }
+ ,{ hostString : 'icloud.com:80:80', description : false }
+ ,{ hostString : 'icloud.com:', description : false }
+ ,{ hostString : ':80', description : false }
+ ,{ hostString : ':', description : false }
+ ,{ hostString : '', description : "empty string" }
+ ];
+
+ if (testIndex >= testCasesThatShouldNotBeAccepted.length) {
+ if (window.testRunner)
+ testRunner.notifyDone();
+ } else {
+ // Prepare for next test case by setting testCaseOnload to load the test case
+ // and then load the simple HTML file that says "Before"
+ testCaseOnload = function () {
+
+ // Prepare test case execution by first setting testCaseOnload to check
+ // the test outcome and then load set the iframe's document.location.host
+ testCaseOnload = function(currentTestIndex) {
+ return function () {
+ if (iframeDocument.location.host == document.location.host) {
+ var currentCase = testCasesThatShouldNotBeAccepted[currentTestIndex],
+ description = (currentCase.description ? currentCase.description : currentCase.hostString);
+ log("PASS: " + description + " was not accepted.\n");
+ runOneTestThatShouldNotBeAccepted(currentTestIndex + 1);
+ } else {
+ // Fails may very well become 404s so this log message might not be triggered
+ log("FAIL: " + description + " was accepted, or at least the iframeDocument.location.host had changed to " + iframeDocument.location.host + "\n");
+ }
+ };
+ }(testIndex);
+
+ iframeDocument.location.host = testCasesThatShouldNotBeAccepted[testIndex].hostString;
+ };
+
+ iframeDocument.location = "./resources/set-document-location-iframe.html";
+ }
+ }
+
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+</script>
+<iframe id="targetFrame" src="resources/set-document-location-iframe.html" onload="iframeOnload()"></iframe>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomsetdocumentlocationhostnametounacceptedvaluesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values-expected.txt        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+PASS: 'icl' + '\uf877' + 'oud.com' was not accepted.
+PASS: icloud.com:-1 was not accepted.
+PASS: icloud.com:11c was not accepted.
+PASS: icloud.com:11 was not accepted.
+PASS: icloud.com:80: was not accepted.
+PASS: icloud.com:80:80 was not accepted.
+PASS: icloud.com: was not accepted.
+PASS: :80 was not accepted.
+PASS: : was not accepted.
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomsetdocumentlocationhostnametounacceptedvalueshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/set-document-location-hostname-to-unaccepted-values.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,76 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Test for setting document.location.hostname to unaccepted values</title>
+</head>
+<body>
+<pre id="pre"></pre>
+<script>
+ // This function will be redefined as the test cases get executed
+ var testCaseOnload = function() {
+ runOneTestThatShouldNotBeAccepted(0);
+ };
+
+ var iframeDocument;
+ function iframeOnload() {
+ iframeDocument = document.getElementById("targetFrame").contentDocument;
+ testCaseOnload();
+ }
+
+ function log(s) {
+ document.getElementById("pre").appendChild(document.createTextNode(s));
+ }
+
+ function runOneTestThatShouldNotBeAccepted(testIndex) {
+ var testCasesThatShouldNotBeAccepted = [
+ { hostString : 'icl' + '\uf877' + 'oud.com', description : "'icl' + '\\uf877' + 'oud.com'" }
+ ,{ hostString : 'icloud.com:-1', description : false }
+ ,{ hostString : 'icloud.com:11c', description : false }
+ ,{ hostString : 'icloud.com:11', description : false }
+ ,{ hostString : 'icloud.com:80:', description : false }
+ ,{ hostString : 'icloud.com:80:80', description : false }
+ ,{ hostString : 'icloud.com:', description : false }
+ ,{ hostString : ':80', description : false }
+ ,{ hostString : ':', description : false }
+ ];
+
+ if (testIndex >= testCasesThatShouldNotBeAccepted.length) {
+ if (window.testRunner)
+ testRunner.notifyDone();
+ } else {
+ // Prepare for next test case by setting testCaseOnload to load the test case
+ // and then load the simple HTML file that says "Before"
+ testCaseOnload = function () {
+
+ // Prepare test case execution by first setting testCaseOnload to check
+ // the test outcome and then load set the iframe's document.location.hostname
+ testCaseOnload = function(currentTestIndex) {
+ return function () {
+ if (iframeDocument.location.host == document.location.host) {
+ var currentCase = testCasesThatShouldNotBeAccepted[currentTestIndex],
+ description = (currentCase.description ? currentCase.description : currentCase.hostString);
+ log("PASS: " + description + " was not accepted.\n");
+ runOneTestThatShouldNotBeAccepted(currentTestIndex + 1);
+ } else {
+ // Fails may very well become 404s so this log message might not be triggered
+ log("FAIL: " + description + " was accepted, or at least the iframeDocument.location.host had changed to " + iframeDocument.location.host + "\n");
+ }
+ };
+ }(testIndex);
+
+ iframeDocument.location.hostname = testCasesThatShouldNotBeAccepted[testIndex].hostString;
+ };
+
+ iframeDocument.location = "./resources/set-document-location-iframe.html";
+ }
+ }
+
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+</script>
+<iframe id="targetFrame" src="resources/set-document-location-iframe.html" onload="iframeOnload()"></iframe>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsdomresourcessetdocumentlocationiframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/dom/resources/set-document-location-iframe.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/dom/resources/set-document-location-iframe.html         (rev 0)
+++ trunk/LayoutTests/http/tests/dom/resources/set-document-location-iframe.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Dummy document to load before document.location test cases</title>
+</head>
+<body>
+<p id="status">
+ Before
+</p>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsdomsetdocumentlocationhosttoacceptedvaluesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values-expected.txt (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values-expected.txt         (rev 0)
+++ trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values-expected.txt        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+CONSOLE MESSAGE: line 66: Blocked a frame with origin "http://127.0.0.1:8000" from accessing a frame with origin "http://localhost:8000". Protocols, domains, and ports must match.
+PASS: localhost:8000 was accepted (at least the iframe contentDocument was null so it had changed origin).
+PASS: 127.0.0.1:8000 was accepted.
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsdomsetdocumentlocationhosttoacceptedvalueshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values.html         (rev 0)
+++ trunk/LayoutTests/http/tests/dom/set-document-location-host-to-accepted-values.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,68 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Test for setting document.location.host to accepted values</title>
+</head>
+<body>
+<pre id="pre"></pre>
+<script>
+ // This function will be redefined as the test cases get executed
+ var testCaseOnload = function() {
+ runOneTestThatShouldBeAccepted(0);
+ };
+
+ var iframeDocument;
+ function iframeOnload() {
+ iframeDocument = document.getElementById("targetFrame").contentDocument;
+ testCaseOnload();
+ }
+
+ function log(s) {
+ document.getElementById("pre").appendChild(document.createTextNode(s));
+ }
+
+ function runOneTestThatShouldBeAccepted(testIndex) {
+ var testCasesThatShouldBeAccepted = [
+ { hostString : 'localhost:8000', description : false }
+ ,{ hostString : '127.0.0.1:8000', description : false }
+ ];
+
+ if (testIndex >= testCasesThatShouldBeAccepted.length) {
+ if (window.testRunner)
+ testRunner.notifyDone();
+ } else {
+ // Prepare for next test case by setting testCaseOnload to load the test case
+ // and then load the simple HTML file that says "Before"
+ testCaseOnload = function () {
+
+ // Prepare test case execution by first setting testCaseOnload to check
+ // the test outcome and then load set the iframe's document.location.host
+ testCaseOnload = function(currentTestIndex) {
+ return function () {
+ var currentCase = testCasesThatShouldBeAccepted[currentTestIndex],
+ description = (currentCase.description ? currentCase.description : currentCase.hostString);
+ if (iframeDocument === null || iframeDocument.location.host == currentCase.hostString) {
+ log("PASS: " + description + " was accepted" + (iframeDocument === null ? " (at least the iframe contentDocument was null so it had changed origin)" : "") + ".\n");
+ } else {
+ log("FAIL: " + description + " was not accepted. The iframe contentDocument was not null and its location.host was not " + currentCase.hostString + ".\n");
+ }
+ runOneTestThatShouldBeAccepted(currentTestIndex + 1);
+ };
+ }(testIndex);
+
+ iframeDocument.location.host = testCasesThatShouldBeAccepted[testIndex].hostString;
+ };
+
+ document.getElementById("targetFrame").setAttribute("src", "http://127.0.0.1:8000/dom/resources/set-document-location-iframe.html");
+ }
+ }
+
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+</script>
+<iframe id="targetFrame" src="resources/set-document-location-iframe.html" onload="iframeOnload()"></iframe>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsdomsetdocumentlocationhostnametoacceptedvaluesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt         (rev 0)
+++ trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values-expected.txt        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+CONSOLE MESSAGE: line 67: Blocked a frame with origin "http://127.0.0.1:8000" from accessing a frame with origin "http://localhost:8000". Protocols, domains, and ports must match.
+PASS: localhost was accepted (at least the iframe contentDocument was null so it had changed origin).
+PASS: 127.0.0.1 was accepted.
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsdomsetdocumentlocationhostnametoacceptedvalueshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values.html (0 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values.html         (rev 0)
+++ trunk/LayoutTests/http/tests/dom/set-document-location-hostname-to-accepted-values.html        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -0,0 +1,69 @@
</span><ins>+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Test for setting document.location.hostname to accepted values</title>
+</head>
+<body>
+<pre id="pre"></pre>
+<script>
+ // This function will be redefined as the test cases get executed
+ var testCaseOnload = function() {
+ runOneTestThatShouldBeAccepted(0);
+ };
+
+ var iframeDocument;
+ function iframeOnload() {
+ iframeDocument = document.getElementById("targetFrame").contentDocument;
+ testCaseOnload();
+ }
+
+ function log(s) {
+ document.getElementById("pre").appendChild(document.createTextNode(s));
+ }
+
+ function runOneTestThatShouldBeAccepted(testIndex) {
+ var testCasesThatShouldBeAccepted = [
+ { hostString : 'localhost', description : false }
+ ,{ hostString : '127.0.0.1', description : false }
+ ];
+
+ if (testIndex >= testCasesThatShouldBeAccepted.length) {
+ if (window.testRunner)
+ testRunner.notifyDone();
+ } else {
+ // Prepare for next test case by setting testCaseOnload to load the test case
+ // and then load the simple HTML file that says "Before"
+ testCaseOnload = function () {
+
+ // Prepare test case execution by first setting testCaseOnload to check
+ // the test outcome and then load set the iframe's document.location.hostname
+ testCaseOnload = function(currentTestIndex) {
+ return function () {
+ var currentCase = testCasesThatShouldBeAccepted[currentTestIndex],
+ description = (currentCase.description ? currentCase.description : currentCase.hostString);
+ if (iframeDocument === null || iframeDocument.location.hostname == currentCase.hostString) {
+ log("PASS: " + description + " was accepted" + (iframeDocument === null ? " (at least the iframe contentDocument was null so it had changed origin)" : "") + ".\n");
+ } else {
+ log("FAIL: " + description + " was not accepted. The iframe contentDocument was not null and its location.hostname was not " + currentCase.hostString + ".\n");
+ }
+ runOneTestThatShouldBeAccepted(currentTestIndex + 1);
+ };
+ }(testIndex);
+
+ iframeDocument.location.hostname = testCasesThatShouldBeAccepted[testIndex].hostString;
+ };
+
+ document.getElementById("targetFrame").setAttribute("src", "http://127.0.0.1:8000/dom/resources/set-document-location-iframe.html");
+ }
+ }
+
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+</script>
+<iframe id="targetFrame" src="resources/set-document-location-iframe.html" onload="iframeOnload()"></iframe>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201849 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-06-09 02:41:01 UTC (rev 201849)
+++ trunk/Source/WebCore/ChangeLog        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-06-08 John Wilander <wilander@apple.com>
+
+ Perform IDNA encoding on parameters for setHostAndPort and setHost
+ https://bugs.webkit.org/show_bug.cgi?id=158371
+ <rdar://problem/16869342>
+
+ Reviewed by Brent Fulgham.
+
+ Tests: fast/dom/set-document-location-host-to-unaccepted-values.html
+ fast/dom/set-document-location-hostname-to-unaccepted-values.html
+ http/tests/dom/set-document-location-host-to-accepted-values.html
+ http/tests/dom/set-document-location-hostname-to-accepted-values.html
+
+ * platform/URL.cpp:
+ (WebCore::containsOnlyASCII):
+ Moved up to enable usage in URL::setHost and URL::setHostAndPort.
+ (WebCore::appendEncodedHostname):
+ Moved up to enable usage in URL::setHost and URL::setHostAndPort.
+ (WebCore::URL::setHost):
+ Now disallows the colon character, does IDNA encoding, and uses StringBuilder.
+ (WebCore::URL::setHostAndPort):
+ Now disallows multiple colons, disallows non-numeric ports, disallows the empty
+ string, does IDNA encoding, and uses StringBuilder.
+
</ins><span class="cx"> 2016-06-08 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Fix WinCairo build.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.cpp (201849 => 201850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.cpp        2016-06-09 02:41:01 UTC (rev 201849)
+++ trunk/Source/WebCore/platform/URL.cpp        2016-06-09 05:07:24 UTC (rev 201850)
</span><span class="lines">@@ -836,17 +836,70 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool containsOnlyASCII(StringView string)
+{
+ if (string.is8Bit())
+ return charactersAreAllASCII(string.characters8(), string.length());
+ return charactersAreAllASCII(string.characters16(), string.length());
+}
+
+// Appends the punycoded hostname identified by the given string and length to
+// the output buffer. The result will not be null terminated.
+// Return value of false means error in encoding.
+static bool appendEncodedHostname(UCharBuffer& buffer, StringView string)
+{
+ // Needs to be big enough to hold an IDN-encoded name.
+ // For host names bigger than this, we won't do IDN encoding, which is almost certainly OK.
+ const unsigned hostnameBufferLength = 2048;
+
+ if (string.length() > hostnameBufferLength || containsOnlyASCII(string)) {
+ append(buffer, string);
+ return true;
+ }
+
+ UChar hostnameBuffer[hostnameBufferLength];
+ UErrorCode error = U_ZERO_ERROR;
+
+#if COMPILER(GCC_OR_CLANG)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ int32_t numCharactersConverted = uidna_IDNToASCII(string.upconvertedCharacters(), string.length(), hostnameBuffer,
+ hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, 0, &error);
+#if COMPILER(GCC_OR_CLANG)
+#pragma GCC diagnostic pop
+#endif
+
+ if (error == U_ZERO_ERROR) {
+ buffer.append(hostnameBuffer, numCharactersConverted);
+ return true;
+ }
+ return false;
+}
+
</ins><span class="cx"> void URL::setHost(const String& s)
</span><span class="cx"> {
</span><span class="cx"> if (!m_isValid)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- // FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
- // and to avoid changing more than just the host.
</del><ins>+ auto colonIndex = s.find(':');
+ if (colonIndex != notFound)
+ return;
</ins><span class="cx">
</span><ins>+ UCharBuffer encodedHostName;
+ if (!appendEncodedHostname(encodedHostName, s))
+ return;
+
</ins><span class="cx"> bool slashSlashNeeded = m_userStart == m_schemeEnd + 1;
</span><del>-
- parse(m_string.left(hostStart()) + (slashSlashNeeded ? "//" : "") + s + m_string.substring(m_hostEnd));
</del><ins>+
+ StringBuilder builder;
+ builder.append(m_string.left(hostStart()));
+ if (slashSlashNeeded)
+ builder.append("//");
+ builder.append(StringView(encodedHostName.data(), encodedHostName.size()));
+ builder.append(m_string.substring(m_hostEnd));
+
+ parse(builder.toString());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void URL::removePort()
</span><span class="lines">@@ -872,12 +925,40 @@
</span><span class="cx"> if (!m_isValid)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- // FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
- // and to avoid changing more than just host and port.
</del><ins>+ StringView hostName(hostAndPort);
+ StringView port;
+
+ auto colonIndex = hostName.find(':');
+ if (colonIndex != notFound) {
+ port = hostName.substring(colonIndex + 1);
+ bool ok;
+ int portInt = port.toIntStrict(ok);
+ if (!ok || portInt < 0)
+ return;
+ hostName = hostName.substring(0, colonIndex);
+ }
</ins><span class="cx">
</span><ins>+ if (hostName.isEmpty())
+ return;
+
+ UCharBuffer encodedHostName;
+ if (!appendEncodedHostname(encodedHostName, hostName))
+ return;
+
</ins><span class="cx"> bool slashSlashNeeded = m_userStart == m_schemeEnd + 1;
</span><span class="cx">
</span><del>- parse(m_string.left(hostStart()) + (slashSlashNeeded ? "//" : "") + hostAndPort + m_string.substring(m_portEnd));
</del><ins>+ StringBuilder builder;
+ builder.append(m_string.left(hostStart()));
+ if (slashSlashNeeded)
+ builder.append("//");
+ builder.append(StringView(encodedHostName.data(), encodedHostName.size()));
+ if (!port.isEmpty()) {
+ builder.append(":");
+ builder.append(port);
+ }
+ builder.append(m_string.substring(m_portEnd));
+
+ parse(builder.toString());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void URL::setUser(const String& user)
</span><span class="lines">@@ -1664,13 +1745,6 @@
</span><span class="cx"> return String(buffer.data(), p - buffer.data());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool containsOnlyASCII(StringView string)
-{
- if (string.is8Bit())
- return charactersAreAllASCII(string.characters8(), string.length());
- return charactersAreAllASCII(string.characters16(), string.length());
-}
-
</del><span class="cx"> static bool protocolIs(StringView stringURL, const char* protocol)
</span><span class="cx"> {
</span><span class="cx"> assertProtocolIsGood(protocol);
</span><span class="lines">@@ -1684,40 +1758,6 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-// Appends the punycoded hostname identified by the given string and length to
-// the output buffer. The result will not be null terminated.
-// Return value of false means error in encoding.
-static bool appendEncodedHostname(UCharBuffer& buffer, StringView string)
-{
- // Needs to be big enough to hold an IDN-encoded name.
- // For host names bigger than this, we won't do IDN encoding, which is almost certainly OK.
- const unsigned hostnameBufferLength = 2048;
-
- if (string.length() > hostnameBufferLength || containsOnlyASCII(string)) {
- append(buffer, string);
- return true;
- }
-
- UChar hostnameBuffer[hostnameBufferLength];
- UErrorCode error = U_ZERO_ERROR;
-
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
- int32_t numCharactersConverted = uidna_IDNToASCII(string.upconvertedCharacters(), string.length(), hostnameBuffer,
- hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, 0, &error);
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic pop
-#endif
-
- if (error == U_ZERO_ERROR) {
- buffer.append(hostnameBuffer, numCharactersConverted);
- return true;
- }
- return false;
-}
-
</del><span class="cx"> static void findHostnamesInMailToURL(StringView string, Vector<std::pair<int, int>>& nameRanges)
</span><span class="cx"> {
</span><span class="cx"> // In a mailto: URL, host names come after a '@' character and end with a '>' or ',' or '?' or end of string character.
</span></span></pre>
</div>
</div>
</body>
</html>