<!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>[242284] 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/242284">242284</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2019-03-01 13:32:53 -0800 (Fri, 01 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adjust XMLHttpRequest Content-Type handling
https://bugs.webkit.org/show_bug.cgi?id=184645

Patch by Rob Buis <rbuis@igalia.com> on 2019-03-01
Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Sync test and update test expectation (all PASSes).

* web-platform-tests/xhr/send-content-type-charset-expected.txt:
* web-platform-tests/xhr/send-content-type-charset.htm:

Source/WebCore:

Implement steps 4.4.1.2 and 4.4.1.3 of send() [1].

Test: web-platform-tests/xhr/send-content-type-charset.htm

[1] https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send

* platform/network/ParsedContentType.cpp:
(WebCore::ParsedContentType::setCharset):
* platform/network/ParsedContentType.h:
* xml/XMLHttpRequest.cpp:
(WebCore::replaceCharsetInMediaTypeIfNeeded):
(WebCore::XMLHttpRequest::send):
(WebCore::replaceCharsetInMediaType): Deleted.

LayoutTests:

Fix 2 subtest expectations.

* http/tests/xmlhttprequest/request-encoding2.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestrequestencoding2html">trunk/LayoutTests/http/tests/xmlhttprequest/request-encoding2.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsxhrsendcontenttypecharsetexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsxhrsendcontenttypecharsethtm">trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset.htm</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkParsedContentTypecpp">trunk/Source/WebCore/platform/network/ParsedContentType.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkParsedContentTypeh">trunk/Source/WebCore/platform/network/ParsedContentType.h</a></li>
<li><a href="#trunkSourceWebCorexmlXMLHttpRequestcpp">trunk/Source/WebCore/xml/XMLHttpRequest.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/LayoutTests/ChangeLog 2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2019-03-01  Rob Buis  <rbuis@igalia.com>
+
+        Adjust XMLHttpRequest Content-Type handling
+        https://bugs.webkit.org/show_bug.cgi?id=184645
+
+        Reviewed by Youenn Fablet.
+
+        Fix 2 subtest expectations.
+
+        * http/tests/xmlhttprequest/request-encoding2.html:
+
</ins><span class="cx"> 2019-03-01  Truitt Savell  <tsavell@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Continued gardening of storage/indexeddb/ crashes after r242189
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestrequestencoding2html"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/xmlhttprequest/request-encoding2.html (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/request-encoding2.html       2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/request-encoding2.html  2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx">         req.send("");
</span><span class="cx"> 
</span><span class="cx">         document.getElementById("result3").firstChild.data = "Test3 (setRequestHeader was called with a non-UTF8 charset):";
</span><del>-        if (req.responseText == "application/xml; charset=UTF-8\n")
</del><ins>+        if (req.responseText == "application/xml;charset=UTF-8\n")
</ins><span class="cx">             document.getElementById("result3").firstChild.data += " SUCCESS";
</span><span class="cx">         else
</span><span class="cx">             document.getElementById("result3").firstChild.data += " FAILURE: '" + req.responseText + "'";
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx">         req.send("");
</span><span class="cx"> 
</span><span class="cx">         document.getElementById("result4").firstChild.data = "Test4 (setRequestHeader was called with multiple charsets and other attributes):";
</span><del>-        if (req.responseText == "application/xml; charset=UTF-8; charset=UTF-8; charset=UTF-8; KOI8-R\n")
</del><ins>+        if (req.responseText == "application/xml;charset=UTF-8\n")
</ins><span class="cx">             document.getElementById("result4").firstChild.data += " SUCCESS";
</span><span class="cx">         else
</span><span class="cx">             document.getElementById("result4").firstChild.data += " FAILURE: '" + req.responseText + "'";
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2019-03-01  Rob Buis  <rbuis@igalia.com>
+
+        Adjust XMLHttpRequest Content-Type handling
+        https://bugs.webkit.org/show_bug.cgi?id=184645
+
+        Reviewed by Youenn Fablet.
+
+        Sync test and update test expectation (all PASSes).
+
+        * web-platform-tests/xhr/send-content-type-charset-expected.txt:
+        * web-platform-tests/xhr/send-content-type-charset.htm:
+
</ins><span class="cx"> 2019-03-01  Antoine Quint  <graouts@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Enable WPT Pointer Events tests
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsxhrsendcontenttypecharsetexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset-expected.txt (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset-expected.txt     2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset-expected.txt        2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -1,20 +1,21 @@
</span><span class="cx"> 
</span><del>-FAIL header with invalid MIME type is not changed assert_equals: expected "text; charset=ascii" but got "text; charset=UTF-8"
</del><ins>+PASS header with invalid MIME type is not changed 
</ins><span class="cx"> PASS header with invalid MIME type (empty string) is not changed 
</span><span class="cx"> PASS known charset but bogus header - missing MIME type 
</span><span class="cx"> PASS bogus charset and bogus header - missing MIME type 
</span><del>-FAIL If charset= param is UTF-8 (case-insensitive), it should not be changed assert_equals: expected "text/plain;charset=utf-8" but got "text/plain;charset=UTF-8"
</del><ins>+PASS If charset= param is UTF-8 (case-insensitive), it should not be changed 
</ins><span class="cx"> PASS If no charset= param is given, implementation should not add one - unknown MIME 
</span><span class="cx"> PASS If no charset= param is given, implementation should not add one - known MIME 
</span><span class="cx"> PASS If no charset= param is given, implementation should not add one - known MIME, unknown param, two spaces 
</span><del>-FAIL charset given but wrong, fix it (unknown MIME, bogus charset) assert_equals: expected "text/x-thepiano;charset=UTF-8" but got "text/x-thepiano;charset= UTF-8"
-FAIL If charset= param is UTF-8 (case-insensitive), it should not be changed (bogus charset) assert_equals: expected "text/plain;charset=utf-8;charset=waddup" but got "text/plain;charset=UTF-8;charset=UTF-8"
</del><ins>+PASS charset given but wrong, fix it (unknown MIME, bogus charset) 
+PASS If charset= param is UTF-8 (case-insensitive), it should not be changed (bogus charset) 
</ins><span class="cx"> PASS charset given but wrong, fix it (known MIME, actual charset) 
</span><del>-FAIL Multiple non-UTF-8 charset parameters deduplicate, bogus parameter dropped assert_equals: expected "text/x-pink-unicorn;charset=UTF-8" but got "text/x-pink-unicorn; charset=UTF-8; charset=UTF-8; notrelated; charset=UTF-8"
</del><ins>+PASS Multiple non-UTF-8 charset parameters deduplicate, bogus parameter dropped 
</ins><span class="cx"> PASS No content type set, give MIME and charset 
</span><del>-FAIL charset with space that is UTF-8 does not change assert_equals: expected "text/plain;charset= utf-8" but got "text/plain;charset= UTF-8"
-FAIL charset in double quotes that is UTF-8 does not change assert_equals: expected "text/plain;charset=\"utf-8\"" but got "text/plain;charset=\"UTF-8\""
-FAIL charset in double quotes with space assert_equals: expected "text/plain;charset=UTF-8" but got "text/plain;charset=\" UTF-8\""
-FAIL charset in double quotes with backslashes that is UTF-8 does not change assert_equals: expected "text/plain;charset=\"u\\t\f-8\"" but got "text/plain;charset=\"UTF-8\""
-FAIL unknown parameters need to be preserved assert_equals: expected "yo/yo;charset=UTF-8;yo=YO;x=y" but got "YO/yo;charset=UTF-8;yo=YO; X=y"
</del><ins>+PASS charset with leading space that is UTF-8 does change 
+PASS charset with trailing space that is UTF-8 does not change 
+PASS charset in double quotes that is UTF-8 does not change 
+PASS charset in double quotes with space 
+PASS charset in double quotes with backslashes that is UTF-8 does not change 
+PASS unknown parameters need to be preserved 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsxhrsendcontenttypecharsethtm"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset.htm (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset.htm      2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/send-content-type-charset.htm 2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -88,9 +88,13 @@
</span><span class="cx">       )
</span><span class="cx">       request(
</span><span class="cx">         "text/plain;charset= utf-8",
</span><del>-        "text/plain;charset= utf-8",
-        "charset with space that is UTF-8 does not change")
</del><ins>+       "text/plain;charset=UTF-8",
+       "charset with leading space that is UTF-8 does change")
</ins><span class="cx">       request(
</span><ins>+        "text/plain;charset=utf-8 ;x=x",
+        "text/plain;charset=utf-8 ;x=x",
+        "charset with trailing space that is UTF-8 does not change");
+      request(
</ins><span class="cx">         "text/plain;charset=\"utf-8\"",
</span><span class="cx">         "text/plain;charset=\"utf-8\"",
</span><span class="cx">         "charset in double quotes that is UTF-8 does not change")
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/Source/WebCore/ChangeLog      2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2019-03-01  Rob Buis  <rbuis@igalia.com>
+
+        Adjust XMLHttpRequest Content-Type handling
+        https://bugs.webkit.org/show_bug.cgi?id=184645
+
+        Reviewed by Youenn Fablet.
+
+        Implement steps 4.4.1.2 and 4.4.1.3 of send() [1].
+
+        Test: web-platform-tests/xhr/send-content-type-charset.htm
+
+        [1] https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
+
+        * platform/network/ParsedContentType.cpp:
+        (WebCore::ParsedContentType::setCharset):
+        * platform/network/ParsedContentType.h:
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::replaceCharsetInMediaTypeIfNeeded):
+        (WebCore::XMLHttpRequest::send):
+        (WebCore::replaceCharsetInMediaType): Deleted.
+
</ins><span class="cx"> 2019-03-01  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Update originsMatch to handle the case of file origins which enforce file path separation
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkParsedContentTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ParsedContentType.cpp (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ParsedContentType.cpp      2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.cpp 2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -346,6 +346,11 @@
</span><span class="cx">     return parameterValueForName("charset");
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ParsedContentType::setCharset(String&& charset)
+{
+    m_parameterValues.set("charset"_s, WTFMove(charset));
+}
+
</ins><span class="cx"> String ParsedContentType::parameterValueForName(const String& name) const
</span><span class="cx"> {
</span><span class="cx">     return m_parameterValues.get(name);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkParsedContentTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ParsedContentType.h (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ParsedContentType.h        2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.h   2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -50,6 +50,7 @@
</span><span class="cx"> 
</span><span class="cx">     String mimeType() const { return m_mimeType; }
</span><span class="cx">     String charset() const;
</span><ins>+    void setCharset(String&&);
</ins><span class="cx"> 
</span><span class="cx">     // Note that in the case of multiple values for the same name, the last value is returned.
</span><span class="cx">     String parameterValueForName(const String&) const;
</span></span></pre></div>
<a id="trunkSourceWebCorexmlXMLHttpRequestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (242283 => 242284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp      2019-03-01 21:31:05 UTC (rev 242283)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2019-03-01 21:32:53 UTC (rev 242284)
</span><span class="lines">@@ -74,23 +74,14 @@
</span><span class="cx">     XMLHttpRequestSendArrayBufferOrViewMax,
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-static void replaceCharsetInMediaType(String& mediaType, const String& charsetValue)
</del><ins>+static void replaceCharsetInMediaTypeIfNeeded(String& mediaType)
</ins><span class="cx"> {
</span><del>-    unsigned pos = 0, len = 0;
-
-    findCharsetInMediaType(mediaType, pos, len);
-
-    if (!len) {
-        // When no charset found, do nothing.
</del><ins>+    auto parsedContentType = ParsedContentType::create(mediaType);
+    if (!parsedContentType || parsedContentType->charset().isEmpty() || equalIgnoringASCIICase(parsedContentType->charset(), "UTF-8"))
</ins><span class="cx">         return;
</span><del>-    }
</del><span class="cx"> 
</span><del>-    // Found at least one existing charset, replace all occurrences with new charset.
-    while (len) {
-        mediaType.replace(pos, len, charsetValue);
-        unsigned start = pos + charsetValue.length();
-        findCharsetInMediaType(mediaType, pos, len, start);
-    }
</del><ins>+    parsedContentType->setCharset("UTF-8");
+    mediaType = parsedContentType->serialize();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void logConsoleError(ScriptExecutionContext* context, const String& message)
</span><span class="lines">@@ -476,7 +467,7 @@
</span><span class="cx">                 m_requestHeaders.set(HTTPHeaderName::ContentType, document.isHTMLDocument() ? "text/html;charset=UTF-8"_s : "application/xml;charset=UTF-8"_s);
</span><span class="cx">         } else {
</span><span class="cx">             String contentType = m_requestHeaders.get(HTTPHeaderName::ContentType);
</span><del>-            replaceCharsetInMediaType(contentType, "UTF-8");
</del><ins>+            replaceCharsetInMediaTypeIfNeeded(contentType);
</ins><span class="cx">             m_requestHeaders.set(HTTPHeaderName::ContentType, contentType);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -505,7 +496,7 @@
</span><span class="cx"> #endif
</span><span class="cx">                 m_requestHeaders.set(HTTPHeaderName::ContentType, HTTPHeaderValues::textPlainContentType());
</span><span class="cx">         } else {
</span><del>-            replaceCharsetInMediaType(contentType, "UTF-8");
</del><ins>+            replaceCharsetInMediaTypeIfNeeded(contentType);
</ins><span class="cx">             m_requestHeaders.set(HTTPHeaderName::ContentType, contentType);
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>