<!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
&lt;rdar://problem/16869342&gt;

Patch by John Wilander &lt;wilander@apple.com&gt; 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  &lt;wilander@apple.com&gt;
+
+        Perform IDNA encoding on parameters for setHostAndPort and setHost
+        https://bugs.webkit.org/show_bug.cgi?id=158371
+        &lt;rdar://problem/16869342&gt;
+
+        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  &lt;ryanhaddad@apple.com&gt;
</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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Dummy document to load before document.location test cases&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p id=&quot;status&quot;&gt;
+    Before
+&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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:11 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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Test for setting document.location.host to unaccepted values&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;pre id=&quot;pre&quot;&gt;&lt;/pre&gt;
+&lt;script&gt;
+    // This function will be redefined as the test cases get executed
+    var testCaseOnload = function() {
+        runOneTestThatShouldNotBeAccepted(0);
+    };
+
+    var iframeDocument;
+    function iframeOnload() {
+        iframeDocument = document.getElementById(&quot;targetFrame&quot;).contentDocument;
+        testCaseOnload();
+    }
+
+    function log(s) {
+        document.getElementById(&quot;pre&quot;).appendChild(document.createTextNode(s));
+    }
+
+    function runOneTestThatShouldNotBeAccepted(testIndex) {
+        var testCasesThatShouldNotBeAccepted = [
+            { hostString : 'icl' + '\uf877' + 'oud.com', description : &quot;'icl' + '\\uf877' + 'oud.com'&quot; }
+            ,{ hostString : 'icloud.com:-1', description : false }
+            ,{ hostString : 'icloud.com:11c', description : false }
+            ,{ hostString : 'icloud.com:11', 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 : &quot;empty string&quot; }
+        ];
+
+        if (testIndex &gt;= 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 &quot;Before&quot;
+            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(&quot;PASS: &quot; + description + &quot; was not accepted.\n&quot;);
+                            runOneTestThatShouldNotBeAccepted(currentTestIndex + 1);
+                        } else {
+                            // Fails may very well become 404s so this log message might not be triggered
+                            log(&quot;FAIL: &quot; + description + &quot; was accepted, or at least the iframeDocument.location.host had changed to &quot; + iframeDocument.location.host + &quot;\n&quot;);
+                        }
+                    };
+                }(testIndex);
+
+                iframeDocument.location.host = testCasesThatShouldNotBeAccepted[testIndex].hostString;
+            };
+
+            iframeDocument.location = &quot;./resources/set-document-location-iframe.html&quot;;
+        }
+    }
+
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;iframe id=&quot;targetFrame&quot; src=&quot;resources/set-document-location-iframe.html&quot; onload=&quot;iframeOnload()&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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:11 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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Test for setting document.location.hostname to unaccepted values&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;pre id=&quot;pre&quot;&gt;&lt;/pre&gt;
+&lt;script&gt;
+    // This function will be redefined as the test cases get executed
+    var testCaseOnload = function() {
+        runOneTestThatShouldNotBeAccepted(0);
+    };
+
+    var iframeDocument;
+    function iframeOnload() {
+        iframeDocument = document.getElementById(&quot;targetFrame&quot;).contentDocument;
+        testCaseOnload();
+    }
+
+    function log(s) {
+        document.getElementById(&quot;pre&quot;).appendChild(document.createTextNode(s));
+    }
+
+    function runOneTestThatShouldNotBeAccepted(testIndex) {
+        var testCasesThatShouldNotBeAccepted = [
+            { hostString : 'icl' + '\uf877' + 'oud.com', description : &quot;'icl' + '\\uf877' + 'oud.com'&quot; }
+            ,{ hostString : 'icloud.com:-1', description : false }
+            ,{ hostString : 'icloud.com:11c', description : false }
+            ,{ hostString : 'icloud.com:11', 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 &gt;= 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 &quot;Before&quot;
+            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(&quot;PASS: &quot; + description + &quot; was not accepted.\n&quot;);
+                            runOneTestThatShouldNotBeAccepted(currentTestIndex + 1);
+                        } else {
+                            // Fails may very well become 404s so this log message might not be triggered
+                            log(&quot;FAIL: &quot; + description + &quot; was accepted, or at least the iframeDocument.location.host had changed to &quot; + iframeDocument.location.host + &quot;\n&quot;);
+                        }
+                    };
+                }(testIndex);
+
+                iframeDocument.location.hostname = testCasesThatShouldNotBeAccepted[testIndex].hostString;
+            };
+
+            iframeDocument.location = &quot;./resources/set-document-location-iframe.html&quot;;
+        }
+    }
+
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;iframe id=&quot;targetFrame&quot; src=&quot;resources/set-document-location-iframe.html&quot; onload=&quot;iframeOnload()&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Dummy document to load before document.location test cases&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p id=&quot;status&quot;&gt;
+    Before
+&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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 &quot;http://127.0.0.1:8000&quot; from accessing a frame with origin &quot;http://localhost:8000&quot;. 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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Test for setting document.location.host to accepted values&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;pre id=&quot;pre&quot;&gt;&lt;/pre&gt;
+&lt;script&gt;
+    // This function will be redefined as the test cases get executed
+    var testCaseOnload = function() {
+        runOneTestThatShouldBeAccepted(0);
+    };
+
+    var iframeDocument;
+    function iframeOnload() {
+        iframeDocument = document.getElementById(&quot;targetFrame&quot;).contentDocument;
+        testCaseOnload();
+    }
+
+    function log(s) {
+        document.getElementById(&quot;pre&quot;).appendChild(document.createTextNode(s));
+    }
+
+    function runOneTestThatShouldBeAccepted(testIndex) {
+        var testCasesThatShouldBeAccepted = [
+            { hostString : 'localhost:8000', description : false }
+            ,{ hostString : '127.0.0.1:8000', description : false }
+        ];
+
+        if (testIndex &gt;= 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 &quot;Before&quot;
+            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(&quot;PASS: &quot; + description + &quot; was accepted&quot; + (iframeDocument === null ? &quot; (at least the iframe contentDocument was null so it had changed origin)&quot; : &quot;&quot;) + &quot;.\n&quot;);
+                        } else {
+                            log(&quot;FAIL: &quot; + description + &quot; was not accepted. The iframe contentDocument was not null and its location.host was not &quot; + currentCase.hostString + &quot;.\n&quot;);
+                        }
+                        runOneTestThatShouldBeAccepted(currentTestIndex + 1);
+                    };
+                }(testIndex);
+
+                iframeDocument.location.host = testCasesThatShouldBeAccepted[testIndex].hostString;
+            };
+
+            document.getElementById(&quot;targetFrame&quot;).setAttribute(&quot;src&quot;, &quot;http://127.0.0.1:8000/dom/resources/set-document-location-iframe.html&quot;);
+        }
+    }
+
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;iframe id=&quot;targetFrame&quot; src=&quot;resources/set-document-location-iframe.html&quot; onload=&quot;iframeOnload()&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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 &quot;http://127.0.0.1:8000&quot; from accessing a frame with origin &quot;http://localhost:8000&quot;. 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>+&lt;!DOCTYPE html&gt;
+&lt;html lang=&quot;en&quot;&gt;
+&lt;head&gt;
+    &lt;meta charset=&quot;UTF-8&quot;&gt;
+    &lt;title&gt;Test for setting document.location.hostname to accepted values&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;pre id=&quot;pre&quot;&gt;&lt;/pre&gt;
+&lt;script&gt;
+    // This function will be redefined as the test cases get executed
+    var testCaseOnload = function() {
+        runOneTestThatShouldBeAccepted(0);
+    };
+
+    var iframeDocument;
+    function iframeOnload() {
+        iframeDocument = document.getElementById(&quot;targetFrame&quot;).contentDocument;
+        testCaseOnload();
+    }
+
+    function log(s) {
+        document.getElementById(&quot;pre&quot;).appendChild(document.createTextNode(s));
+    }
+
+    function runOneTestThatShouldBeAccepted(testIndex) {
+        var testCasesThatShouldBeAccepted = [
+            { hostString : 'localhost', description : false }
+            ,{ hostString : '127.0.0.1', description : false }
+        ];
+
+        if (testIndex &gt;= 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 &quot;Before&quot;
+            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(&quot;PASS: &quot; + description + &quot; was accepted&quot; + (iframeDocument === null ? &quot; (at least the iframe contentDocument was null so it had changed origin)&quot; : &quot;&quot;) + &quot;.\n&quot;);
+                        } else {
+                            log(&quot;FAIL: &quot; + description + &quot; was not accepted. The iframe contentDocument was not null and its location.hostname was not &quot; + currentCase.hostString + &quot;.\n&quot;);
+                        }
+                        runOneTestThatShouldBeAccepted(currentTestIndex + 1);
+                    };
+                }(testIndex);
+
+                iframeDocument.location.hostname = testCasesThatShouldBeAccepted[testIndex].hostString;
+            };
+
+            document.getElementById(&quot;targetFrame&quot;).setAttribute(&quot;src&quot;, &quot;http://127.0.0.1:8000/dom/resources/set-document-location-iframe.html&quot;);
+        }
+    }
+
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+&lt;/script&gt;
+&lt;iframe id=&quot;targetFrame&quot; src=&quot;resources/set-document-location-iframe.html&quot; onload=&quot;iframeOnload()&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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  &lt;wilander@apple.com&gt;
+
+        Perform IDNA encoding on parameters for setHostAndPort and setHost
+        https://bugs.webkit.org/show_bug.cgi?id=158371
+        &lt;rdar://problem/16869342&gt;
+
+        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  &lt;achristensen@webkit.org&gt;
</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&amp; 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() &gt; 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 &quot;-Wdeprecated-declarations&quot;
+#endif
+    int32_t numCharactersConverted = uidna_IDNToASCII(string.upconvertedCharacters(), string.length(), hostnameBuffer,
+        hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, 0, &amp;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&amp; 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 ? &quot;//&quot; : &quot;&quot;) + s + m_string.substring(m_hostEnd));
</del><ins>+    
+    StringBuilder builder;
+    builder.append(m_string.left(hostStart()));
+    if (slashSlashNeeded)
+        builder.append(&quot;//&quot;);
+    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 &lt; 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 ? &quot;//&quot; : &quot;&quot;) + hostAndPort + m_string.substring(m_portEnd));
</del><ins>+    StringBuilder builder;
+    builder.append(m_string.left(hostStart()));
+    if (slashSlashNeeded)
+        builder.append(&quot;//&quot;);
+    builder.append(StringView(encodedHostName.data(), encodedHostName.size()));
+    if (!port.isEmpty()) {
+        builder.append(&quot;:&quot;);
+        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&amp; 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&amp; 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() &gt; 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 &quot;-Wdeprecated-declarations&quot;
-#endif
-    int32_t numCharactersConverted = uidna_IDNToASCII(string.upconvertedCharacters(), string.length(), hostnameBuffer,
-        hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, 0, &amp;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&lt;std::pair&lt;int, int&gt;&gt;&amp; nameRanges)
</span><span class="cx"> {
</span><span class="cx">     // In a mailto: URL, host names come after a '@' character and end with a '&gt;' or ',' or '?' or end of string character.
</span></span></pre>
</div>
</div>

</body>
</html>