<!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>[179933] 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/179933">179933</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2015-02-11 10:03:42 -0800 (Wed, 11 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>URL::setUser and URL::setPass don't percent encode
https://bugs.webkit.org/show_bug.cgi?id=141453
rdar://problem/14844503&amp;16551802&amp;19623145

Reviewed by Darin Adler.

Source/WebCore:

Tests: fast/url/url-credentials-escaping.html
       http/tests/xmlhttprequest/basic-auth-credentials-escaping.html

Start adding some code that performs escaping in a way that matches the URL Standard.
Right now, it's only used where we failed to do any escaping at all, and over time,
we'll be moving towards a new implementation.

* html/URLUtils.h:
(WebCore::URLUtils&lt;T&gt;::username):
(WebCore::URLUtils&lt;T&gt;::password):
* platform/URL.cpp:
(WebCore::isSchemeFirstChar):
(WebCore::URL::user):
(WebCore::URL::pass):
(WebCore::URL::encodedUser):
(WebCore::URL::encodedPass):
(WebCore::URL::setUser):
(WebCore::URL::setPass):
(WebCore::encodeWithURLEscapeSequences):
* platform/URL.h:

LayoutTests:

* fast/url/url-credentials-escaping-expected.txt: Added.
* fast/url/url-credentials-escaping.html: Added.
This change is most directly testable via URL API.

* http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt: Added.
* http/tests/xmlhttprequest/basic-auth-credentials-escaping.html: Added.
Verify that this doesn't break XMLHttpRequest authentication.

* fast/dom/DOMURL/invalid-url-getters-expected.txt: Removed.
* fast/dom/DOMURL/invalid-url-getters.html: Removed.
* fast/dom/DOMURL/url-origin-expected.txt:
* fast/dom/DOMURL/url-origin.html:
Removed tests for invalid URLs, there is no such thing with URL API.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastdomDOMURLurloriginexpectedtxt">trunk/LayoutTests/fast/dom/DOMURL/url-origin-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomDOMURLurloriginhtml">trunk/LayoutTests/fast/dom/DOMURL/url-origin.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlURLUtilsh">trunk/Source/WebCore/html/URLUtils.h</a></li>
<li><a href="#trunkSourceWebCoreplatformURLcpp">trunk/Source/WebCore/platform/URL.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformURLh">trunk/Source/WebCore/platform/URL.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasturlurlcredentialsescapingexpectedtxt">trunk/LayoutTests/fast/url/url-credentials-escaping-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasturlurlcredentialsescapinghtml">trunk/LayoutTests/fast/url/url-credentials-escaping.html</a></li>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestbasicauthcredentialsescapingexpectedtxt">trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestbasicauthcredentialsescapinghtml">trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping.html</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomDOMURLinvalidurlgettersexpectedtxt">trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomDOMURLinvalidurlgettershtml">trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/LayoutTests/ChangeLog        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2015-02-10  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        URL::setUser and URL::setPass don't percent encode
+        https://bugs.webkit.org/show_bug.cgi?id=141453
+        rdar://problem/14844503&amp;16551802&amp;19623145
+
+        Reviewed by Darin Adler.
+
+        * fast/url/url-credentials-escaping-expected.txt: Added.
+        * fast/url/url-credentials-escaping.html: Added.
+        This change is most directly testable via URL API.
+
+        * http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt: Added.
+        * http/tests/xmlhttprequest/basic-auth-credentials-escaping.html: Added.
+        Verify that this doesn't break XMLHttpRequest authentication.
+
+        * fast/dom/DOMURL/invalid-url-getters-expected.txt: Removed.
+        * fast/dom/DOMURL/invalid-url-getters.html: Removed.
+        * fast/dom/DOMURL/url-origin-expected.txt:
+        * fast/dom/DOMURL/url-origin.html:
+        Removed tests for invalid URLs, there is no such thing with URL API.
+
</ins><span class="cx"> 2015-02-11  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r179921.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomDOMURLinvalidurlgettersexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters-expected.txt (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters-expected.txt        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters-expected.txt        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -1,19 +0,0 @@
</span><del>-Test what getters return on an invalid URL
-
-On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
-
-
-PASS invalidURL.toString() is 'http://@@:p@www.example.com:22/bar?x#y'
-FAIL invalidURL.origin should be . Was null.
-PASS invalidURL.username is ''
-PASS invalidURL.password is ''
-PASS invalidURL.host is ''
-PASS invalidURL.hostname is ''
-PASS invalidURL.port is ''
-PASS invalidURL.pathname is ''
-PASS invalidURL.search is ''
-PASS invalidURL.hash is ''
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
</del></span></pre></div>
<a id="trunkLayoutTestsfastdomDOMURLinvalidurlgettershtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters.html (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters.html        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/LayoutTests/fast/dom/DOMURL/invalid-url-getters.html        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -1,29 +0,0 @@
</span><del>-&lt;!DOCTYPE html&gt;
-&lt;html&gt;
-&lt;head&gt;
-&lt;meta charset=&quot;utf-8&quot;&gt;
-&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
-&lt;/head&gt;
-&lt;body&gt;
-&lt;script&gt;
-
-description(&quot;Test what getters return on an invalid URL&quot;);
-
-var invalidURL = new URL(&quot;http://u:p@www.example.com:22/bar?x#y&quot;)
-invalidURL.username = &quot;@@&quot;;
-
-shouldBe(&quot;invalidURL.toString()&quot;, &quot;'http://@@:p@www.example.com:22/bar?x#y'&quot;);
-shouldBe(&quot;invalidURL.origin&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.username&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.password&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.host&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.hostname&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.port&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.pathname&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.search&quot;, &quot;''&quot;);
-shouldBe(&quot;invalidURL.hash&quot;, &quot;''&quot;);
-
-&lt;/script&gt;
-&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
-&lt;/body&gt;
-&lt;/html&gt;
</del></span></pre></div>
<a id="trunkLayoutTestsfastdomDOMURLurloriginexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/DOMURL/url-origin-expected.txt (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/DOMURL/url-origin-expected.txt        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/LayoutTests/fast/dom/DOMURL/url-origin-expected.txt        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -4,5 +4,4 @@
</span><span class="cx"> ftp://example.com/ttt?ggg =&gt; ftp://example.com
</span><span class="cx"> file:///home/abarth =&gt; file://
</span><span class="cx"> data:text/html,&lt;b&gt;foo&lt;/b&gt; =&gt; null
</span><del>-http://@@@www.example.com/bar =&gt; null
</del><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomDOMURLurloriginhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/DOMURL/url-origin.html (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/DOMURL/url-origin.html        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/LayoutTests/fast/dom/DOMURL/url-origin.html        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -5,9 +5,6 @@
</span><span class="cx"> if (window.testRunner)
</span><span class="cx">     testRunner.dumpAsText();
</span><span class="cx"> 
</span><del>-var invalidURL = new URL(&quot;http://www.example.com/bar&quot;)
-invalidURL.username = &quot;@@&quot;;
-
</del><span class="cx"> var cases = [
</span><span class="cx">     new URL(&quot;http://example.com/foo/bar&quot;),
</span><span class="cx">     new URL(&quot;HTTP://example.com/foo/bar&quot;),
</span><span class="lines">@@ -15,7 +12,6 @@
</span><span class="cx">     new URL(&quot;ftp://example.com/ttt?ggg&quot;),
</span><span class="cx">     new URL(&quot;file:///home/abarth&quot;),
</span><span class="cx">     new URL(&quot;data:text/html,&lt;b&gt;foo&lt;/b&gt;&quot;),
</span><del>-    invalidURL
</del><span class="cx"> ];
</span><span class="cx"> 
</span><span class="cx"> window.onload = function(e)
</span></span></pre></div>
<a id="trunkLayoutTestsfasturlurlcredentialsescapingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/url/url-credentials-escaping-expected.txt (0 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/url/url-credentials-escaping-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/url/url-credentials-escaping-expected.txt        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -0,0 +1,51 @@
</span><ins>+Test that URL username and password accessors encode/decode correctly
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+
+Basic syntax
+PASS build('user').toString() is &quot;http://user@www.apple.com/&quot;
+PASS build('user').username is &quot;user&quot;
+PASS build('%').toString() is &quot;http://%@www.apple.com/&quot;
+PASS build('%').username is &quot;%&quot;
+PASS build('%%').toString() is &quot;http://%%@www.apple.com/&quot;
+PASS build('%%').username is &quot;%%&quot;
+PASS build('%z').toString() is &quot;http://%z@www.apple.com/&quot;
+PASS build('%z').username is &quot;%z&quot;
+PASS build('%61').toString() is &quot;http://%61@www.apple.com/&quot;
+PASS build('%61').username is &quot;%61&quot;
+PASS build('%40').toString() is &quot;http://%40@www.apple.com/&quot;
+PASS build('%40').username is &quot;%40&quot;
+
+Simple encode set
+PASS build('').toString() is &quot;http://%07%7F@www.apple.com/&quot;
+PASS build('user', '').toString() is &quot;http://user:%07%7F@www.apple.com/&quot;
+
+Default encode set additions
+PASS build(' &quot;#&gt;&lt;?`').toString() is &quot;http://%20%22%23%3E%3C%3F%60@www.apple.com/&quot;
+PASS build('user', ' &quot;#&gt;&lt;?`').toString() is &quot;http://user:%20%22%23%3E%3C%3F%60@www.apple.com/&quot;
+
+Password encode set additions
+PASS build('/@\\').toString() is &quot;http://%2F%40%5C@www.apple.com/&quot;
+PASS build('user', '/@\\').toString() is &quot;http://user:%2F%40%5C@www.apple.com/&quot;
+':' shouldn't be encoded in the password per the URL Standard, although both Firefox and Chrome encode it
+PASS build('user', ':').toString() is &quot;http://user::@www.apple.com/&quot;
+
+Username encode set addition
+PASS build(':').toString() is &quot;http://%3A@www.apple.com/&quot;
+
+8-bit
+PASS build('юзер', 'пароль').toString() is &quot;http://%D1%8E%D0%B7%D0%B5%D1%80:%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C@www.apple.com/&quot;
+PASS build('юзер').username is &quot;%D1%8E%D0%B7%D0%B5%D1%80&quot;
+PASS build('user', 'пароль').password is &quot;%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C&quot;
+
+Some special characters that don't get encoded when used in credentials
+PASS build('!$&amp;*()-+~').toString() is &quot;http://!$&amp;*()-+~@www.apple.com/&quot;
+
+Some characters that shouldn't be encoded per the URL Standard, although both Firefox and Chrome encode them
+PASS build('^{|}[]=').toString() is &quot;http://^{|}[]=@www.apple.com/&quot;
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/url/url-credentials-escaping-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfasturlurlcredentialsescapinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/url/url-credentials-escaping.html (0 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/url/url-credentials-escaping.html                                (rev 0)
+++ trunk/LayoutTests/fast/url/url-credentials-escaping.html        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -0,0 +1,72 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;meta charset=&quot;utf-8&quot;&gt;
+&lt;script src=&quot;../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+
+description(&quot;Test that URL username and password accessors encode/decode correctly&quot;);
+
+function build(username, password)
+{
+    var url = new URL(&quot;http://www.apple.com&quot;);
+    if (username)
+        url.username = username;
+    if (password)
+        url.password = password;
+    return url;
+}
+
+debug(&quot;\nBasic syntax&quot;);
+
+shouldBe(&quot;build('user').toString()&quot;, '&quot;http://user@www.apple.com/&quot;');
+shouldBe(&quot;build('user').username&quot;, '&quot;user&quot;');
+
+shouldBe(&quot;build('%').toString()&quot;, '&quot;http://%@www.apple.com/&quot;');
+shouldBe(&quot;build('%').username&quot;, '&quot;%&quot;');
+
+shouldBe(&quot;build('%%').toString()&quot;, '&quot;http://%%@www.apple.com/&quot;');
+shouldBe(&quot;build('%%').username&quot;, '&quot;%%&quot;');
+
+shouldBe(&quot;build('%z').toString()&quot;, '&quot;http://%z@www.apple.com/&quot;');
+shouldBe(&quot;build('%z').username&quot;, '&quot;%z&quot;');
+
+// Yes, this is weird, percent signs don't get encoded.
+shouldBe(&quot;build('%61').toString()&quot;, '&quot;http://%61@www.apple.com/&quot;');
+shouldBe(&quot;build('%61').username&quot;, '&quot;%61&quot;');
+shouldBe(&quot;build('%40').toString()&quot;, '&quot;http://%40@www.apple.com/&quot;');
+shouldBe(&quot;build('%40').username&quot;, '&quot;%40&quot;');
+
+debug(&quot;\nSimple encode set&quot;);
+shouldBe(&quot;build('\x07\x7f').toString()&quot;, '&quot;http://%07%7F@www.apple.com/&quot;');
+shouldBe(&quot;build('user', '\x07\x7f').toString()&quot;, '&quot;http://user:%07%7F@www.apple.com/&quot;');
+
+debug(&quot;\nDefault encode set additions&quot;);
+shouldBe(&quot;build(' \&quot;#&gt;&lt;?`').toString()&quot;, '&quot;http://%20%22%23%3E%3C%3F%60@www.apple.com/&quot;');
+shouldBe(&quot;build('user', ' \&quot;#&gt;&lt;?`').toString()&quot;, '&quot;http://user:%20%22%23%3E%3C%3F%60@www.apple.com/&quot;');
+
+debug(&quot;\nPassword encode set additions&quot;);
+shouldBe(&quot;build('/@\\\\').toString()&quot;, '&quot;http://%2F%40%5C@www.apple.com/&quot;');
+shouldBe(&quot;build('user', '/@\\\\').toString()&quot;, '&quot;http://user:%2F%40%5C@www.apple.com/&quot;');
+debug(&quot;':' shouldn't be encoded in the password per the URL Standard, although both Firefox and Chrome encode it&quot;)
+shouldBe(&quot;build('user', ':').toString()&quot;, '&quot;http://user::@www.apple.com/&quot;');
+
+debug(&quot;\nUsername encode set addition&quot;);
+shouldBe(&quot;build(':').toString()&quot;, '&quot;http://%3A@www.apple.com/&quot;');
+
+debug(&quot;\n8-bit&quot;);
+shouldBe(&quot;build('юзер', 'пароль').toString()&quot;, '&quot;http://%D1%8E%D0%B7%D0%B5%D1%80:%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C@www.apple.com/&quot;');
+shouldBe(&quot;build('юзер').username&quot;, '&quot;%D1%8E%D0%B7%D0%B5%D1%80&quot;');
+shouldBe(&quot;build('user', 'пароль').password&quot;, '&quot;%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C&quot;');
+
+debug(&quot;\nSome special characters that don't get encoded when used in credentials&quot;);
+shouldBe(&quot;build('!$&amp;*()-+~').toString()&quot;, '&quot;http://!$&amp;*()-+~@www.apple.com/&quot;');
+
+debug(&quot;\nSome characters that shouldn't be encoded per the URL Standard, although both Firefox and Chrome encode them&quot;)
+shouldBe(&quot;build('^{|}[]=').toString()&quot;, '&quot;http://^{|}[]=@www.apple.com/&quot;');
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/url/url-credentials-escaping.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestbasicauthcredentialsescapingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt (0 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+Tests for XMLHttpRequest authentication.
+
+async: User: 1, password: %a%.
+async2: User: 2, password: @.
+async3: User: 3, password: @.
+async4: User: 4, password: :.
+async5: User: 5, password: .
+async6: User: 6, password: a.
+async7: User: 7, password: /@\ &quot;#&gt;&lt;?`.
</ins><span class="cx">Property changes on: trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestbasicauthcredentialsescapinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping.html (0 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping.html        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -0,0 +1,95 @@
</span><ins>+&lt;html&gt;
+&lt;meta charset=&quot;utf-8&quot;&gt;
+&lt;body&gt;
+&lt;p&gt;Tests for XMLHttpRequest authentication.
+&lt;script&gt;
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+    
+    var console_messages = document.createElement(&quot;ol&quot;);
+    document.body.appendChild(console_messages);
+    
+    function log(message)
+    {
+        var item = document.createElement(&quot;li&quot;);
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+
+    function sendAndLogResponse(uid, req)
+    {
+        try {
+            req.send(&quot;&quot;);
+            log(uid + ': ' + req.responseText);
+        } catch (e) {
+            log(uid + &quot;: req.send raised exception: &quot; + e);
+            log(uid + &quot;: req.readyState: &quot; + req.readyState);
+            log(uid + &quot;: req.status: &quot; + req.status);
+        }
+    }
+
+    // async
+    var asyncStep = 1;
+
+    req = new XMLHttpRequest;
+    req.onreadystatechange = processStateChange;
+    req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=1&quot;, true, &quot;1&quot;, &quot;%a%&quot;);
+    req.send(&quot;&quot;);
+
+    function processStateChange() {
+    
+      if (req.readyState == 4){
+        if (req.status == 200){
+          if (asyncStep == 1) {
+            asyncStep = 2;
+            log('async: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=2&quot;, true, &quot;2&quot;, &quot;%40&quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 2) {
+            asyncStep = 3;
+            log('async2: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=3&quot;, true, &quot;3&quot;, &quot;@&quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 3) {
+            asyncStep = 4;
+            log('async3: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=4&quot;, true, &quot;4&quot;, &quot;:&quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 4) {
+            asyncStep = 5;
+            log('async4: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=5&quot;, true, &quot;5&quot;, &quot; &quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 5) {
+            asyncStep = 6;
+            log('async5: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=6&quot;, true, &quot;6&quot;, &quot;%61&quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 6) {
+            asyncStep = 7;
+            log('async6: ' + req.responseText);
+            req.onreadystatechange = processStateChange;
+            req.open(&quot;GET&quot;, &quot;resources/basic-auth/basic-auth.php?uid=7&quot;, true, &quot;7&quot;, &quot;/@\\ \&quot;#&gt;&lt;?`&quot;);
+            req.send(&quot;&quot;);
+          } else if (asyncStep == 7) {
+            log('async7: ' + req.responseText);
+            if (window.testRunner)
+              testRunner.notifyDone();
+          }
+        } else {
+            log(&quot;async&quot; + asyncStep + &quot; failed with unexpected status: &quot; + req.status + &quot;. Response: '&quot; + req.responseText + &quot;'.&quot;);
+            if (window.testRunner)
+              testRunner.notifyDone();
+        }
+      }
+    }
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/http/tests/xmlhttprequest/basic-auth-credentials-escaping.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/Source/WebCore/ChangeLog        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2015-02-10  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        URL::setUser and URL::setPass don't percent encode
+        https://bugs.webkit.org/show_bug.cgi?id=141453
+        rdar://problem/14844503&amp;16551802&amp;19623145
+
+        Reviewed by Darin Adler.
+
+        Tests: fast/url/url-credentials-escaping.html
+               http/tests/xmlhttprequest/basic-auth-credentials-escaping.html
+
+        Start adding some code that performs escaping in a way that matches the URL Standard.
+        Right now, it's only used where we failed to do any escaping at all, and over time,
+        we'll be moving towards a new implementation.
+
+        * html/URLUtils.h:
+        (WebCore::URLUtils&lt;T&gt;::username):
+        (WebCore::URLUtils&lt;T&gt;::password):
+        * platform/URL.cpp:
+        (WebCore::isSchemeFirstChar):
+        (WebCore::URL::user):
+        (WebCore::URL::pass):
+        (WebCore::URL::encodedUser):
+        (WebCore::URL::encodedPass):
+        (WebCore::URL::setUser):
+        (WebCore::URL::setPass):
+        (WebCore::encodeWithURLEscapeSequences):
+        * platform/URL.h:
+
</ins><span class="cx"> 2015-02-11  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Add a few more WEBCORE_EXPORT macros for debug and iOS builds.
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlURLUtilsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/URLUtils.h (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/URLUtils.h        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/Source/WebCore/html/URLUtils.h        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -98,7 +98,7 @@
</span><span class="cx"> template &lt;typename T&gt;
</span><span class="cx"> String URLUtils&lt;T&gt;::username() const
</span><span class="cx"> {
</span><del>-    return href().user();
</del><ins>+    return href().encodedUser();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename T&gt;
</span><span class="lines">@@ -112,7 +112,7 @@
</span><span class="cx"> template &lt;typename T&gt;
</span><span class="cx"> String URLUtils&lt;T&gt;::password() const
</span><span class="cx"> {
</span><del>-    return href().pass();
</del><ins>+    return href().encodedPass();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename T&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.cpp (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.cpp        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/Source/WebCore/platform/URL.cpp        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2004, 2007, 2008, 2011, 2012, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2004, 2007, 2008, 2011, 2012, 2013, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -233,6 +233,108 @@
</span><span class="cx">     /* 252 */ BadChar, /* 253 */ BadChar, /* 254 */ BadChar, /* 255 */ BadChar
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+enum PercentEncodeCharacterClass {
+    // Class names match the URL Standard; each class is a superset of the previous one.
+    PercentEncodeSimple = 255,
+    PercentEncodeDefault = 127,
+    PercentEncodePassword = 63,
+    PercentEncodeUsername = 31,
+};
+
+static const unsigned char percentEncodeClassTable[256] = {
+    /* 0 nul */ PercentEncodeSimple,    /* 1 soh */ PercentEncodeSimple,    /* 2 stx */ PercentEncodeSimple,    /* 3 etx */ PercentEncodeSimple,
+    /* 4 eot */ PercentEncodeSimple,    /* 5 enq */ PercentEncodeSimple,    /* 6 ack */ PercentEncodeSimple,    /* 7 bel */ PercentEncodeSimple,
+    /* 8 bs */ PercentEncodeSimple,     /* 9 ht */ PercentEncodeSimple,     /* 10 nl */ PercentEncodeSimple,    /* 11 vt */ PercentEncodeSimple,
+    /* 12 np */ PercentEncodeSimple,    /* 13 cr */ PercentEncodeSimple,    /* 14 so */ PercentEncodeSimple,    /* 15 si */ PercentEncodeSimple,
+    /* 16 dle */ PercentEncodeSimple,   /* 17 dc1 */ PercentEncodeSimple,   /* 18 dc2 */ PercentEncodeSimple,   /* 19 dc3 */ PercentEncodeSimple,
+    /* 20 dc4 */ PercentEncodeSimple,   /* 21 nak */ PercentEncodeSimple,   /* 22 syn */ PercentEncodeSimple,   /* 23 etb */ PercentEncodeSimple,
+    /* 24 can */ PercentEncodeSimple,   /* 25 em */ PercentEncodeSimple,    /* 26 sub */ PercentEncodeSimple,   /* 27 esc */ PercentEncodeSimple,
+    /* 28 fs */ PercentEncodeSimple,    /* 29 gs */ PercentEncodeSimple,    /* 30 rs */ PercentEncodeSimple,    /* 31 us */ PercentEncodeSimple,
+    /* 32 sp */ PercentEncodeDefault,
+    /* 33  ! */ 0,
+    /* 34  &quot; */ PercentEncodeDefault,
+    /* 35  # */ PercentEncodeDefault,
+    /* 36  $ */ 0,
+    /* 37  % */ 0,
+    /* 38  &amp; */ 0,
+    /* 39  ' */ 0,
+    /* 40  ( */ 0,
+    /* 41  ) */ 0,
+    /* 42  * */ 0,
+    /* 43  + */ 0,
+    /* 44  , */ 0,
+    /* 45  - */ 0,
+    /* 46  . */ 0,
+    /* 47  / */ PercentEncodePassword,
+    /* 48  0 */ 0,    /* 49  1 */ 0,    /* 50  2 */ 0,    /* 51  3 */ 0,
+    /* 52  4 */ 0,    /* 53  5 */ 0,    /* 54  6 */ 0,    /* 55  7 */ 0,
+    /* 56  8 */ 0,    /* 57  9 */ 0,
+    /* 58  : */ PercentEncodeUsername,
+    /* 59  ; */ 0,
+    /* 60  &lt; */ PercentEncodeDefault,
+    /* 61  = */ 0,
+    /* 62  &gt; */ PercentEncodeDefault,
+    /* 63  ? */ PercentEncodeDefault,
+    /* 64  @ */ PercentEncodePassword,
+    /* 65  A */ 0,    /* 66  B */ 0,    /* 67  C */ 0,    /* 68  D */ 0,
+    /* 69  E */ 0,    /* 70  F */ 0,    /* 71  G */ 0,    /* 72  H */ 0,
+    /* 73  I */ 0,    /* 74  J */ 0,    /* 75  K */ 0,    /* 76  L */ 0,
+    /* 77  M */ 0,    /* 78  N */ 0,    /* 79  O */ 0,    /* 80  P */ 0,
+    /* 81  Q */ 0,    /* 82  R */ 0,    /* 83  S */ 0,    /* 84  T */ 0,
+    /* 85  U */ 0,    /* 86  V */ 0,    /* 87  W */ 0,    /* 88  X */ 0,
+    /* 89  Y */ 0,    /* 90  Z */ 0,
+    /* 91  [ */ 0,
+    /* 92  \ */ PercentEncodePassword,
+    /* 93  ] */ 0,
+    /* 94  ^ */ 0,
+    /* 95  _ */ 0,
+    /* 96  ` */ PercentEncodeDefault,
+    /* 97  a */ 0,    /* 98  b */ 0,    /* 99  c */ 0,    /* 100  d */ 0,
+    /* 101  e */ 0,    /* 102  f */ 0,    /* 103  g */ 0,    /* 104  h */ 0,
+    /* 105  i */ 0,    /* 106  j */ 0,    /* 107  k */ 0,    /* 108  l */ 0,
+    /* 109  m */ 0,    /* 110  n */ 0,    /* 111  o */ 0,    /* 112  p */ 0,
+    /* 113  q */ 0,    /* 114  r */ 0,    /* 115  s */ 0,    /* 116  t */ 0,
+    /* 117  u */ 0,    /* 118  v */ 0,    /* 119  w */ 0,    /* 120  x */ 0,
+    /* 121  y */ 0,    /* 122  z */ 0,
+    /* 123  { */ 0,
+    /* 124  | */ 0,
+    /* 125  } */ 0,
+    /* 126  ~ */ 0,
+    /* 127 del */ PercentEncodeSimple,
+    /* 128 */ PercentEncodeSimple, /* 129 */ PercentEncodeSimple, /* 130 */ PercentEncodeSimple, /* 131 */ PercentEncodeSimple,
+    /* 132 */ PercentEncodeSimple, /* 133 */ PercentEncodeSimple, /* 134 */ PercentEncodeSimple, /* 135 */ PercentEncodeSimple,
+    /* 136 */ PercentEncodeSimple, /* 137 */ PercentEncodeSimple, /* 138 */ PercentEncodeSimple, /* 139 */ PercentEncodeSimple,
+    /* 140 */ PercentEncodeSimple, /* 141 */ PercentEncodeSimple, /* 142 */ PercentEncodeSimple, /* 143 */ PercentEncodeSimple,
+    /* 144 */ PercentEncodeSimple, /* 145 */ PercentEncodeSimple, /* 146 */ PercentEncodeSimple, /* 147 */ PercentEncodeSimple,
+    /* 148 */ PercentEncodeSimple, /* 149 */ PercentEncodeSimple, /* 150 */ PercentEncodeSimple, /* 151 */ PercentEncodeSimple,
+    /* 152 */ PercentEncodeSimple, /* 153 */ PercentEncodeSimple, /* 154 */ PercentEncodeSimple, /* 155 */ PercentEncodeSimple,
+    /* 156 */ PercentEncodeSimple, /* 157 */ PercentEncodeSimple, /* 158 */ PercentEncodeSimple, /* 159 */ PercentEncodeSimple,
+    /* 160 */ PercentEncodeSimple, /* 161 */ PercentEncodeSimple, /* 162 */ PercentEncodeSimple, /* 163 */ PercentEncodeSimple,
+    /* 164 */ PercentEncodeSimple, /* 165 */ PercentEncodeSimple, /* 166 */ PercentEncodeSimple, /* 167 */ PercentEncodeSimple,
+    /* 168 */ PercentEncodeSimple, /* 169 */ PercentEncodeSimple, /* 170 */ PercentEncodeSimple, /* 171 */ PercentEncodeSimple,
+    /* 172 */ PercentEncodeSimple, /* 173 */ PercentEncodeSimple, /* 174 */ PercentEncodeSimple, /* 175 */ PercentEncodeSimple,
+    /* 176 */ PercentEncodeSimple, /* 177 */ PercentEncodeSimple, /* 178 */ PercentEncodeSimple, /* 179 */ PercentEncodeSimple,
+    /* 180 */ PercentEncodeSimple, /* 181 */ PercentEncodeSimple, /* 182 */ PercentEncodeSimple, /* 183 */ PercentEncodeSimple,
+    /* 184 */ PercentEncodeSimple, /* 185 */ PercentEncodeSimple, /* 186 */ PercentEncodeSimple, /* 187 */ PercentEncodeSimple,
+    /* 188 */ PercentEncodeSimple, /* 189 */ PercentEncodeSimple, /* 190 */ PercentEncodeSimple, /* 191 */ PercentEncodeSimple,
+    /* 192 */ PercentEncodeSimple, /* 193 */ PercentEncodeSimple, /* 194 */ PercentEncodeSimple, /* 195 */ PercentEncodeSimple,
+    /* 196 */ PercentEncodeSimple, /* 197 */ PercentEncodeSimple, /* 198 */ PercentEncodeSimple, /* 199 */ PercentEncodeSimple,
+    /* 200 */ PercentEncodeSimple, /* 201 */ PercentEncodeSimple, /* 202 */ PercentEncodeSimple, /* 203 */ PercentEncodeSimple,
+    /* 204 */ PercentEncodeSimple, /* 205 */ PercentEncodeSimple, /* 206 */ PercentEncodeSimple, /* 207 */ PercentEncodeSimple,
+    /* 208 */ PercentEncodeSimple, /* 209 */ PercentEncodeSimple, /* 210 */ PercentEncodeSimple, /* 211 */ PercentEncodeSimple,
+    /* 212 */ PercentEncodeSimple, /* 213 */ PercentEncodeSimple, /* 214 */ PercentEncodeSimple, /* 215 */ PercentEncodeSimple,
+    /* 216 */ PercentEncodeSimple, /* 217 */ PercentEncodeSimple, /* 218 */ PercentEncodeSimple, /* 219 */ PercentEncodeSimple,
+    /* 220 */ PercentEncodeSimple, /* 221 */ PercentEncodeSimple, /* 222 */ PercentEncodeSimple, /* 223 */ PercentEncodeSimple,
+    /* 224 */ PercentEncodeSimple, /* 225 */ PercentEncodeSimple, /* 226 */ PercentEncodeSimple, /* 227 */ PercentEncodeSimple,
+    /* 228 */ PercentEncodeSimple, /* 229 */ PercentEncodeSimple, /* 230 */ PercentEncodeSimple, /* 231 */ PercentEncodeSimple,
+    /* 232 */ PercentEncodeSimple, /* 233 */ PercentEncodeSimple, /* 234 */ PercentEncodeSimple, /* 235 */ PercentEncodeSimple,
+    /* 236 */ PercentEncodeSimple, /* 237 */ PercentEncodeSimple, /* 238 */ PercentEncodeSimple, /* 239 */ PercentEncodeSimple,
+    /* 240 */ PercentEncodeSimple, /* 241 */ PercentEncodeSimple, /* 242 */ PercentEncodeSimple, /* 243 */ PercentEncodeSimple,
+    /* 244 */ PercentEncodeSimple, /* 245 */ PercentEncodeSimple, /* 246 */ PercentEncodeSimple, /* 247 */ PercentEncodeSimple,
+    /* 248 */ PercentEncodeSimple, /* 249 */ PercentEncodeSimple, /* 250 */ PercentEncodeSimple, /* 251 */ PercentEncodeSimple,
+    /* 252 */ PercentEncodeSimple, /* 253 */ PercentEncodeSimple, /* 254 */ PercentEncodeSimple, /* 255 */ PercentEncodeSimple
+};
+
</ins><span class="cx"> static int copyPathRemovingDots(char* dst, const char* src, int srcStart, int srcEnd);
</span><span class="cx"> static void encodeRelativeString(const String&amp; rel, const TextEncoding&amp;, CharBuffer&amp; ouput);
</span><span class="cx"> static String substituteBackslashes(const String&amp;);
</span><span class="lines">@@ -256,6 +358,8 @@
</span><span class="cx">     return (character | 0x20) == schemeCharacter;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String encodeWithURLEscapeSequences(const String&amp; notEncodedString, PercentEncodeCharacterClass whatToEncode);
+
</ins><span class="cx"> // Copies the source to the destination, assuming all the source characters are
</span><span class="cx"> // ASCII. The destination buffer must be large enough. Null characters are allowed
</span><span class="cx"> // in the source string, and no attempt is made to null-terminate the result.
</span><span class="lines">@@ -598,19 +702,32 @@
</span><span class="cx">     return number;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String URL::user() const
+{
+    return decodeURLEscapeSequences(m_string.substring(m_userStart, m_userEnd - m_userStart));
+}
+
</ins><span class="cx"> String URL::pass() const
</span><span class="cx"> {
</span><span class="cx">     if (m_passwordEnd == m_userEnd)
</span><span class="cx">         return String();
</span><span class="cx"> 
</span><del>-    return decodeURLEscapeSequences(m_string.substring(m_userEnd + 1, m_passwordEnd - m_userEnd - 1)); 
</del><ins>+    return decodeURLEscapeSequences(m_string.substring(m_userEnd + 1, m_passwordEnd - m_userEnd - 1));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-String URL::user() const
</del><ins>+String URL::encodedUser() const
</ins><span class="cx"> {
</span><del>-    return decodeURLEscapeSequences(m_string.substring(m_userStart, m_userEnd - m_userStart));
</del><ins>+    return m_string.substring(m_userStart, m_userEnd - m_userStart);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String URL::encodedPass() const
+{
+    if (m_passwordEnd == m_userEnd)
+        return String();
+
+    return m_string.substring(m_userEnd + 1, m_passwordEnd - m_userEnd - 1);
+}
+
</ins><span class="cx"> String URL::fragmentIdentifier() const
</span><span class="cx"> {
</span><span class="cx">     if (m_fragmentEnd == m_queryEnd)
</span><span class="lines">@@ -762,7 +879,7 @@
</span><span class="cx"> 
</span><span class="cx">     int end = m_userEnd;
</span><span class="cx">     if (!user.isEmpty()) {
</span><del>-        String u = user;
</del><ins>+        String u = encodeWithURLEscapeSequences(user, PercentEncodeUsername);
</ins><span class="cx">         if (m_userStart == m_schemeEnd + 1)
</span><span class="cx">             u = &quot;//&quot; + u;
</span><span class="cx">         // Add '@' if we didn't have one before.
</span><span class="lines">@@ -784,12 +901,9 @@
</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 user password.
-
</del><span class="cx">     int end = m_passwordEnd;
</span><span class="cx">     if (!password.isEmpty()) {
</span><del>-        String p = &quot;:&quot; + password + &quot;@&quot;;
</del><ins>+        String p = &quot;:&quot; + encodeWithURLEscapeSequences(password, PercentEncodePassword) + &quot;@&quot;;
</ins><span class="cx">         if (m_userEnd == m_schemeEnd + 1)
</span><span class="cx">             p = &quot;//&quot; + p;
</span><span class="cx">         // Eat the existing '@' since we are going to add our own.
</span><span class="lines">@@ -1478,6 +1592,28 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String encodeWithURLEscapeSequences(const String&amp; notEncodedString, PercentEncodeCharacterClass whatToEncode)
+{
+    CString asUTF8 = notEncodedString.utf8();
+
+    CharBuffer buffer(asUTF8.length() * 3 + 1);
+    char* p = buffer.data();
+
+    const char* str = asUTF8.data();
+    const char* strEnd = str + asUTF8.length();
+    while (str &lt; strEnd) {
+        unsigned char c = *str++;
+        if (percentEncodeClassTable[c] &gt;= whatToEncode)
+            appendEscapedChar(p, c);
+        else
+            *p++ = c;
+    }
+
+    ASSERT(p - buffer.data() &lt;= static_cast&lt;int&gt;(buffer.size()));
+
+    return String(buffer.data(), p - buffer.data());
+}
+
</ins><span class="cx"> String encodeWithURLEscapeSequences(const String&amp; notEncodedString)
</span><span class="cx"> {
</span><span class="cx">     CString asUTF8 = notEncodedString.utf8();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.h (179932 => 179933)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.h        2015-02-11 17:58:33 UTC (rev 179932)
+++ trunk/Source/WebCore/platform/URL.h        2015-02-11 18:03:42 UTC (rev 179933)
</span><span class="lines">@@ -113,6 +113,11 @@
</span><span class="cx">     WEBCORE_EXPORT String fragmentIdentifier() const;
</span><span class="cx">     WEBCORE_EXPORT bool hasFragmentIdentifier() const;
</span><span class="cx"> 
</span><ins>+    // Unlike user() and pass(), these functions don't decode escape sequences.
+    // This is necessary for accurate round-tripping, because encoding doesn't encode '%' characters.
+    String encodedUser() const;
+    String encodedPass() const;
+
</ins><span class="cx">     WEBCORE_EXPORT String baseAsString() const;
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT String fileSystemPath() const;
</span><span class="lines">@@ -253,6 +258,7 @@
</span><span class="cx"> WEBCORE_EXPORT String decodeURLEscapeSequences(const String&amp;);
</span><span class="cx"> String decodeURLEscapeSequences(const String&amp;, const TextEncoding&amp;);
</span><span class="cx"> 
</span><ins>+// FIXME: This is a wrong concept to expose, different parts of a URL need different escaping per the URL Standard.
</ins><span class="cx"> WEBCORE_EXPORT String encodeWithURLEscapeSequences(const String&amp;);
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre>
</div>
</div>

</body>
</html>