Diff
Modified: trunk/LayoutTests/ChangeLog (223216 => 223217)
--- trunk/LayoutTests/ChangeLog 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/ChangeLog 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,3 +1,15 @@
+2017-10-11 Chris Dumez <[email protected]>
+
+ XMLHttpRequest: do not sniff text/html, and do not sniff XML when responseType is set to "text"
+ https://bugs.webkit.org/show_bug.cgi?id=168724
+
+ Reviewed by Ryosuke Niwa.
+
+ Drop outdated test, proper behavior is covered by web-platform-tests.
+
+ * fast/xmlhttprequest/xmlhttprequest-html-response-encoding-expected.txt: Removed.
+ * fast/xmlhttprequest/xmlhttprequest-html-response-encoding.html: Removed.
+
2017-10-11 Ryan Haddad <[email protected]>
Mark imported/w3c/web-platform-tests/XMLHttpRequest/open-url-worker-origin.htm as flaky.
Deleted: trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding-expected.txt (223216 => 223217)
--- trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding-expected.txt 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding-expected.txt 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,4 +0,0 @@
-Test for bug 14288: XMLHttpRequest doesn't use a correct content type for file:// URLs.
-
-HTML, charset determined by a META: Проверка
-Async: HTML, charset determined by a META: Проверка
Deleted: trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding.html (223216 => 223217)
--- trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding.html 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding.html 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,67 +0,0 @@
-<html>
-<head>
-<title>Test XmlHttpRequest response encoding handling</title>
-</head>
-<body>
-<p>Test for <a href="" 14288</a>:
-XMLHttpRequest doesn't use a correct content type for file:// URLs.</p>
-<script>
-
- if (window.testRunner) {
- testRunner.dumpAsText();
- testRunner.waitUntilDone();
- }
-
- var console_messages = document.createElement("ol");
- document.body.appendChild(console_messages);
-
- var asyncStep = 1;
-
- function log(message)
- {
- var item = document.createElement("li");
- item.appendChild(document.createTextNode(message));
- console_messages.appendChild(item);
- }
-
- function get(url, async)
- {
- if (window.XMLHttpRequest) {
- req = new XMLHttpRequest();
- } else {
- try {
- req = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (ex) {
- req = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
-
- if (async)
- req._onreadystatechange_ = processStateChange;
-
- req.open('GET', url, async);
- req.send(null);
-
- return req;
- }
-
- function processStateChange(){
- if (req.readyState == 4) {
- log("Async: HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- if (window.testRunner)
- testRunner.notifyDone();
- }
- }
-
- try {
- req = get('resources/1251.html', false);
- log("HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- get('resources/1251.html', true);
-
-</script>
-</body>
-</html>
Deleted: trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding-expected.txt (223216 => 223217)
--- trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding-expected.txt 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding-expected.txt 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,24 +0,0 @@
-Test for bug 5744 - correctly determine the encoding of XMLHttpRequest responses.
-
-Plain text, UTF-8 as default: Проверка
-Plain text, windows-1251 specified in HTTP headers: Проверка
-Plain text, windows-1251 specified in overrideMimeType: Проверка
-Plain text, koi8-r specified in HTTP headers, but overridden by windows-1251 in overrideMimeType: Проверка
-XML, UTF-8 as default: Проверка. responseText: <?xml version="1.0"?> <node>Проверка</node>
-XML, windows-1251 specified in XML declaration: Проверка. responseText: <?xml version="1.0" encoding="windows-1251"?> <node>Проверка</node>
-XML, koi8-r specified in XML declaration, but overridden by windows-1251 in HTTP headers: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-HTML, charset determined by a META: Проверка
-HTML, UTF-8 as default: Проверка
-Async: Plain text, UTF-8 as default: Проверка
-Async: Plain text, windows-1251 specified in HTTP headers: Проверка
-Async: Plain text, windows-1251 specified in overrideMimeType: Проверка
-Async: Plain text, koi8-r specified in HTTP headers, but overridden by windows-1251 in overrideMimeType: Проверка
-Async: XML, UTF-8 as default: Проверка. responseText: <?xml version="1.0"?> <node>Проверка</node>
-Async: XML, windows-1251 specified in XML declaration: Проверка. responseText: <?xml version="1.0" encoding="windows-1251"?> <node>Проверка</node>
-Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in HTTP headers: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: Проверка. responseText: <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-Async: XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): <?xml version="1.0" encoding="koi8-r"?> <node>Проверка</node>
-Async: HTML, charset determined by a META: Проверка
-Async: HTML, UTF-8 as default: Проверка
Deleted: trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding.html (223216 => 223217)
--- trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding.html 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/response-encoding.html 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,230 +0,0 @@
-<html>
-<head>
-<title>Test XmlHttpRequest response encoding handling</title>
-<meta http-equiv="content-type" content="text/html;charset=koi8-r">
-<body>
-<p>Test for <a href="" 5744</a>
-- correctly determine the encoding of XMLHttpRequest responses.</p>
-<script>
-
- if (window.testRunner) {
- testRunner.dumpAsText();
- testRunner.waitUntilDone();
- }
-
- var console_messages = document.createElement("ol");
- document.body.appendChild(console_messages);
-
- var asyncStep = 1;
-
- function log(message)
- {
- var item = document.createElement("li");
- item.appendChild(document.createTextNode(message));
- console_messages.appendChild(item);
- }
-
- function get(url, async)
- {
- if (window.XMLHttpRequest) {
- req = new XMLHttpRequest();
- } else {
- try {
- req = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (ex) {
- req = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
-
- if (async)
- req._onreadystatechange_ = processStateChange;
-
- req.open('GET', url, async);
- req.send(null);
-
- if (!async && req.status != 200)
- throw ("HTTP request failed, status: " + req.status);
-
- return req;
- }
-
- function getWithOverride(url, contentType, async)
- {
- if (window.XMLHttpRequest) {
- req = new XMLHttpRequest();
- } else {
- try {
- req = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (ex) {
- req = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
-
- if (async)
- req._onreadystatechange_ = processStateChange;
-
- req.open('GET', url, async);
- req.overrideMimeType(contentType);
- req.send(null);
-
- if (!async && req.status != 200)
- throw ("HTTP request failed, status: " + req.status);
-
- return req;
- }
-
- function processStateChange(){
- if (req.readyState == 4){
- if (req.status == 200){
- if (asyncStep == 1) {
- asyncStep = 2;
- log("Async: Plain text, UTF-8 as default: " + req.responseText);
- get('resources/reply2.txt', true);
- } else if (asyncStep == 2) {
- asyncStep = 3;
- log("Async: Plain text, windows-1251 specified in HTTP headers: " + req.responseText);
- getWithOverride('resources/reply3.txt', 'text/plain; charset=windows-1251', true);
- } else if (asyncStep == 3) {
- asyncStep = 4;
- log("Async: Plain text, windows-1251 specified in overrideMimeType: " + req.responseText);
- getWithOverride('resources/reply4.txt', 'text/plain; charset=windows-1251', true);
- } else if (asyncStep == 4) {
- asyncStep = 5;
- log("Async: Plain text, koi8-r specified in HTTP headers, but overridden by windows-1251 in overrideMimeType: " + req.responseText);
- get('resources/reply4.xml', true);
- } else if (asyncStep == 5) {
- asyncStep = 6;
- log("Async: XML, UTF-8 as default: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- get('resources/reply.xml', true);
- } else if (asyncStep == 6) {
- asyncStep = 7;
- log("Async: XML, windows-1251 specified in XML declaration: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- get('resources/reply2.xml', true);
- } else if (asyncStep == 7) {
- asyncStep = 8;
- log("Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in HTTP headers: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- getWithOverride('resources/reply3.xml', 'text/xml; charset=windows-1251', true);
- } else if (asyncStep == 8) {
- asyncStep = 9;
- log("Async: XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: " +
- (req.responseXML ? req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue : "<No responseXML>") + ". responseText: " + req.responseText);
- get('resources/reply5.txt', true);
- } else if (asyncStep == 9) {
- asyncStep = 10;
- log("Async: XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): " + req.responseText);
- get('resources/1251.html', true);
- } else if (asyncStep == 10) {
- asyncStep = 11;
- log("Async: HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- get('resources/utf-8-no-charset.html', true);
- } else if (asyncStep == 11) {
- log("Async: HTML, UTF-8 as default: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- if (window.testRunner)
- testRunner.notifyDone();
- }
- } else {
- log("Error loading URL: status " + req.status);
- }
- }
- }
-
- // sync code
-
- // 1
- try {
- req = get('resources/reply.txt', false);
- log("Plain text, UTF-8 as default: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 2
- try {
- req = get('resources/reply2.txt', false);
- log("Plain text, windows-1251 specified in HTTP headers: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 3
- try {
- req = getWithOverride('resources/reply3.txt', 'text/plain; charset=windows-1251', false);
- log("Plain text, windows-1251 specified in overrideMimeType: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 4
- try {
- req = getWithOverride('resources/reply4.txt', 'text/plain; charset=windows-1251', false);
- log("Plain text, koi8-r specified in HTTP headers, but overridden by windows-1251 in overrideMimeType: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 5
- try {
- req = get('resources/reply4.xml', false);
- log("XML, UTF-8 as default: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 6
- try {
- req = get('resources/reply.xml', false);
- log("XML, windows-1251 specified in XML declaration: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 7
- try {
- req = get('resources/reply2.xml', false);
- log("XML, koi8-r specified in XML declaration, but overridden by windows-1251 in HTTP headers: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 8
- try {
- req = getWithOverride('resources/reply3.xml', 'text/xml; charset=windows-1251', false);
- log("XML, koi8-r specified in XML declaration, but overridden by windows-1251 in overrideMimeType: " + req.responseXML.getElementsByTagName('node')[0].childNodes[0].nodeValue + ". responseText: " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 9
- try {
- req = get('resources/reply5.txt', false);
- log("XML transferred as text/plain, UTF-8 as default (ignore XML text declaration): " + req.responseText);
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 10
- try {
- req = get('resources/1251.html', false);
- log("HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // 11
- try {
- req = get('resources/utf-8-no-charset.html', false);
- log("HTML, UTF-8 as default: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
- } catch (ex) {
- log("Exception: " + ex.description);
- }
-
- // start async steps
- get('resources/reply.txt', true);
-
-// var console = document.createElement("p");
-// console.appendChild(console_messages);
-// document.body.appendChild(console);
-
-</script>
-</body>
-</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (223216 => 223217)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,5 +1,16 @@
2017-10-11 Chris Dumez <[email protected]>
+ XMLHttpRequest: do not sniff text/html, and do not sniff XML when responseType is set to "text"
+ https://bugs.webkit.org/show_bug.cgi?id=168724
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline web-platform-tests now that all checks are passing.
+
+ * web-platform-tests/XMLHttpRequest/responsetext-decoding-expected.txt:
+
+2017-10-11 Chris Dumez <[email protected]>
+
Re-sync XMLHttpRequests Web-Platform-Tests
https://bugs.webkit.org/show_bug.cgi?id=178172
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responsetext-decoding-expected.txt (223216 => 223217)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responsetext-decoding-expected.txt 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/responsetext-decoding-expected.txt 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,6 +1,6 @@
PASS XMLHttpRequest: responseText decoding (application/xml %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty)
-FAIL XMLHttpRequest: responseText decoding (text/html %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty) assert_equals: expected "<!doctype html><meta charset=windows-1252><x>機</x>" but got "<!doctype html><meta charset=windows-1252><x>機</x>"
+PASS XMLHttpRequest: responseText decoding (text/html %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty)
PASS XMLHttpRequest: responseText decoding (application/xml;charset=utf-8 %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty)
PASS XMLHttpRequest: responseText decoding (application/xml;charset=windows-1252 %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty)
PASS XMLHttpRequest: responseText decoding (text/html;charset=utf-8 %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E empty)
@@ -17,8 +17,8 @@
PASS XMLHttpRequest: responseText decoding (text/xml %EF%BB%BF empty)
PASS XMLHttpRequest: responseText decoding (text/xml %EF%BB%BF%EF%BB%BF empty)
PASS XMLHttpRequest: responseText decoding (text/plain %E3%81%B2 empty)
-FAIL XMLHttpRequest: responseText decoding (application/xml %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text) assert_equals: expected "<?xml version='1.0' encoding='windows-1252'?><x>機</x>" but got "<?xml version='1.0' encoding='windows-1252'?><x>機</x>"
-FAIL XMLHttpRequest: responseText decoding (text/html %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text) assert_equals: expected "<!doctype html><meta charset=windows-1252><x>機</x>" but got "<!doctype html><meta charset=windows-1252><x>機</x>"
+PASS XMLHttpRequest: responseText decoding (application/xml %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text)
+PASS XMLHttpRequest: responseText decoding (text/html %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text)
PASS XMLHttpRequest: responseText decoding (application/xml;charset=utf-8 %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text)
PASS XMLHttpRequest: responseText decoding (application/xml;charset=windows-1252 %3C%3Fxml%20version%3D'1.0'%20encoding%3D'windows-1252'%3F%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text)
PASS XMLHttpRequest: responseText decoding (text/html;charset=utf-8 %3C!doctype%20html%3E%3Cmeta%20charset%3Dwindows-1252%3E%3Cx%3E%e6%a9%9f%3C%2Fx%3E text)
Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (223216 => 223217)
--- trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-10-12 00:27:23 UTC (rev 223217)
@@ -451,4 +451,3 @@
[ HighSierra+ ] fast/text/system-font-fallback-emoji.html [ Crash ]
webkit.org/b/177563 [ HighSierra ] http/tests/xmlhttprequest/response-empty-arraybuffer.html [ Failure ]
-webkit.org/b/177564 [ HighSierra ] http/tests/xmlhttprequest/response-encoding.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (223216 => 223217)
--- trunk/Source/WebCore/ChangeLog 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/Source/WebCore/ChangeLog 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1,3 +1,26 @@
+2017-10-11 Chris Dumez <[email protected]>
+
+ XMLHttpRequest: do not sniff text/html, and do not sniff XML when responseType is set to "text"
+ https://bugs.webkit.org/show_bug.cgi?id=168724
+
+ Reviewed by Ryosuke Niwa.
+
+ WebKit enabled HTML / XML charset detection for HTML-ish / XML-ish
+ responses even when response type is text, which does not match the
+ specification.
+
+ This patch is based on the following Blink patch by Yutaka Hirano <[email protected]>:
+ - https://chromium.googlesource.com/chromium/src.git/+/47e4fc53e6d68c0a788fcc26de598b9e3848033f
+
+ Tests:
+ imported/w3c/web-platform-tests/XMLHttpRequest/responsetext-decoding.htm
+ imported/w3c/web-platform-tests/XMLHttpRequest/responsedocument-decoding.htm
+
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::createDecoder const):
+ (WebCore::XMLHttpRequest::didReceiveData):
+ * xml/XMLHttpRequest.h:
+
2017-10-11 Andy Estes <[email protected]>
[Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (223216 => 223217)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2017-10-12 00:27:23 UTC (rev 223217)
@@ -1047,6 +1047,39 @@
return true;
}
+Ref<TextResourceDecoder> XMLHttpRequest::createDecoder() const
+{
+ if (!m_responseEncoding.isEmpty())
+ return TextResourceDecoder::create("text/plain", m_responseEncoding);
+
+ switch (m_responseType) {
+ case ResponseType::EmptyString:
+ if (responseIsXML()) {
+ auto decoder = TextResourceDecoder::create("application/xml");
+ // Don't stop on encoding errors, unlike it is done for other kinds of XML resources. This matches the behavior of previous WebKit versions, Firefox and Opera.
+ decoder->useLenientXMLDecoding();
+ return decoder;
+ }
+ FALLTHROUGH;
+ case ResponseType::Text:
+ case ResponseType::Json:
+ return TextResourceDecoder::create("text/plain", "UTF-8");
+ case ResponseType::Document: {
+ if (equalLettersIgnoringASCIICase(responseMIMEType(), "text/html"))
+ return TextResourceDecoder::create("text/html", "UTF-8");
+ auto decoder = TextResourceDecoder::create("application/xml");
+ // Don't stop on encoding errors, unlike it is done for other kinds of XML resources. This matches the behavior of previous WebKit versions, Firefox and Opera.
+ decoder->useLenientXMLDecoding();
+ return decoder;
+ }
+ case ResponseType::Arraybuffer:
+ case ResponseType::Blob:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ return TextResourceDecoder::create("text/plain", "UTF-8");
+}
+
void XMLHttpRequest::didReceiveData(const char* data, int len)
{
if (m_error)
@@ -1063,19 +1096,8 @@
bool useDecoder = shouldDecodeResponse(m_responseType);
- if (useDecoder && !m_decoder) {
- if (!m_responseEncoding.isEmpty())
- m_decoder = TextResourceDecoder::create("text/plain", m_responseEncoding);
- // allow TextResourceDecoder to look inside the m_response if it's XML or HTML
- else if (responseIsXML()) {
- m_decoder = TextResourceDecoder::create("application/xml");
- // Don't stop on encoding errors, unlike it is done for other kinds of XML resources. This matches the behavior of previous WebKit versions, Firefox and Opera.
- m_decoder->useLenientXMLDecoding();
- } else if (equalLettersIgnoringASCIICase(responseMIMEType(), "text/html"))
- m_decoder = TextResourceDecoder::create("text/html", "UTF-8");
- else
- m_decoder = TextResourceDecoder::create("text/plain", "UTF-8");
- }
+ if (useDecoder && !m_decoder)
+ m_decoder = createDecoder();
if (!len)
return;
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.h (223216 => 223217)
--- trunk/Source/WebCore/xml/XMLHttpRequest.h 2017-10-12 00:17:18 UTC (rev 223216)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.h 2017-10-12 00:27:23 UTC (rev 223217)
@@ -180,6 +180,7 @@
void dispatchErrorEvents(const AtomicString&);
void resumeTimerFired();
+ Ref<TextResourceDecoder> createDecoder() const;
std::unique_ptr<XMLHttpRequestUpload> m_upload;