Bug 184645

Summary: Adjust XMLHttpRequest Content-Type handling
Product: WebKit Reporter: Anne van Kesteren <annevk>
Component: DOMAssignee: Rob Buis <rbuis>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, cdumez, commit-queue, ews-watchlist, rbuis, rniwa, rwlbuis, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 180526, 191085    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews102 for mac-highsierra
none
Patch
none
Patch
none
Patch
none
Patch none

Anne van Kesteren
Reported 2018-04-16 02:49:42 PDT
See https://github.com/whatwg/xhr/pull/176 and https://github.com/w3c/web-platform-tests/pull/8422. In particular, XMLHttpRequest Content-Type manipulation is now to be done in terms of the MIME type parser defined in MIME Sniffing.
Attachments
Patch (8.60 KB, patch)
2019-02-27 12:38 PST, Rob Buis
no flags
Archive of layout-test-results from ews102 for mac-highsierra (2.42 MB, application/zip)
2019-02-27 13:40 PST, EWS Watchlist
no flags
Patch (10.96 KB, patch)
2019-02-27 13:46 PST, Rob Buis
no flags
Patch (10.96 KB, patch)
2019-02-28 00:34 PST, Rob Buis
no flags
Patch (12.08 KB, patch)
2019-03-01 02:26 PST, Rob Buis
no flags
Patch (12.02 KB, patch)
2019-03-01 09:37 PST, Rob Buis
no flags
Anne van Kesteren
Comment 1 2018-10-30 02:50:07 PDT
https://github.com/whatwg/xhr/pull/224 and https://github.com/web-platform-tests/wpt/pull/13779 have minor tweaks to this to make this more web-compatible.
Chris Dumez
Comment 2 2018-10-30 15:38:15 PDT
Test is xhr/send-content-type-charset.htm.
Chris Dumez
Comment 3 2018-10-30 15:49:30 PDT
Quite a few failures on imported/w3c/web-platform-tests/xhr/send-content-type-charset.htm: FAIL header with invalid MIME type is not changed assert_equals: expected "text; charset=ascii" but got "text; charset=UTF-8" PASS header with invalid MIME type (empty string) is not changed PASS known charset but bogus header - missing MIME type PASS bogus charset and bogus header - missing MIME type 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" PASS If no charset= param is given, implementation should not add one - unknown MIME PASS If no charset= param is given, implementation should not add one - known MIME PASS If no charset= param is given, implementation should not add one - known MIME, unknown param, two spaces 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" PASS charset given but wrong, fix it (known MIME, actual charset) 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" PASS No content type set, give MIME and charset 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"
Alexey Proskuryakov
Comment 4 2018-10-30 16:17:54 PDT
I think that the challenge here is to separate cases that have the potential of fixing or breaking websites from irrelevant subtests.
Rob Buis
Comment 5 2019-02-27 12:38:49 PST
EWS Watchlist
Comment 6 2019-02-27 13:40:41 PST
Comment on attachment 363117 [details] Patch Attachment 363117 [details] did not pass mac-ews (mac): Output: https://webkit-queues.webkit.org/results/11306680 New failing tests: http/tests/xmlhttprequest/request-encoding2.html
EWS Watchlist
Comment 7 2019-02-27 13:40:44 PST
Created attachment 363123 [details] Archive of layout-test-results from ews102 for mac-highsierra The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-highsierra Platform: Mac OS X 10.13.6
Rob Buis
Comment 8 2019-02-27 13:46:38 PST
Rob Buis
Comment 9 2019-02-28 00:34:17 PST
youenn fablet
Comment 10 2019-02-28 14:00:11 PST
Comment on attachment 363208 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=363208&action=review > Source/WebCore/platform/network/ParsedContentType.cpp:351 > + m_parameterValues.set("charset", charset); s/"charset"/"charset"_s/ Could also be String&&/WTFMove > Source/WebCore/xml/XMLHttpRequest.cpp:77 > static void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) Can we make replaceCharsetInMediaType closer to spec by no longer passing charsetValue, since it is always UTF-8? We could then change replaceCharsetInMediaType prototype so that it takes a const String& and return a String. > Source/WebCore/xml/XMLHttpRequest.cpp:79 > + Optional<ParsedContentType> parsedContentType = ParsedContentType::create(mediaType); s/Optional<ParsedContentType>/auto/
Rob Buis
Comment 11 2019-03-01 02:26:44 PST
Rob Buis
Comment 12 2019-03-01 08:08:36 PST
Comment on attachment 363208 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=363208&action=review >> Source/WebCore/platform/network/ParsedContentType.cpp:351 >> + m_parameterValues.set("charset", charset); > > s/"charset"/"charset"_s/ > > Could also be String&&/WTFMove Done. >> Source/WebCore/xml/XMLHttpRequest.cpp:77 >> static void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) > > Can we make replaceCharsetInMediaType closer to spec by no longer passing charsetValue, since it is always UTF-8? > We could then change replaceCharsetInMediaType prototype so that it takes a const String& and return a String. Good idea, done. >> Source/WebCore/xml/XMLHttpRequest.cpp:79 >> + Optional<ParsedContentType> parsedContentType = ParsedContentType::create(mediaType); > > s/Optional<ParsedContentType>/auto/ Done.
youenn fablet
Comment 13 2019-03-01 08:23:22 PST
Comment on attachment 363318 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=363318&action=review > Source/WebCore/xml/XMLHttpRequest.cpp:77 > +static String replaceCharsetInMediaType(const String& mediaType) I would rename it to replaceCharsetInMediaTypeIfNeeded. Thinking about it, chances are that mediaType will be returned without any change. We could take a String&& and return a String. Or go back to void/String&. > Source/WebCore/xml/XMLHttpRequest.cpp:84 > + return parsedContentType->serialize(); "text/plain; charset=UTF-8" should remain as is and not become "text/plain;charset=UTF-8", right? Can we add a test if we do not cover this case? > LayoutTests/imported/w3c/ChangeLog:8 > + Sync test and uodate test expectation (all PASSes). s/uodate/update/
Rob Buis
Comment 14 2019-03-01 09:37:23 PST
Rob Buis
Comment 15 2019-03-01 09:40:07 PST
Comment on attachment 363318 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=363318&action=review >> Source/WebCore/xml/XMLHttpRequest.cpp:77 >> +static String replaceCharsetInMediaType(const String& mediaType) > > I would rename it to replaceCharsetInMediaTypeIfNeeded. > Thinking about it, chances are that mediaType will be returned without any change. > We could take a String&& and return a String. Or go back to void/String&. I thought about it but thought the name would get kind of long. Anyway fine with it :) >> Source/WebCore/xml/XMLHttpRequest.cpp:84 >> + return parsedContentType->serialize(); > > "text/plain; charset=UTF-8" should remain as is and not become "text/plain;charset=UTF-8", right? > Can we add a test if we do not cover this case? We pass that, I tried it locally. I would like to cover this case in send-content-type-charset.htm, but in a follow-up commit to WPT. >> LayoutTests/imported/w3c/ChangeLog:8 >> + Sync test and uodate test expectation (all PASSes). > > s/uodate/update/ Fixed.
WebKit Commit Bot
Comment 16 2019-03-01 13:32:59 PST
Comment on attachment 363337 [details] Patch Clearing flags on attachment: 363337 Committed r242284: <https://trac.webkit.org/changeset/242284>
WebKit Commit Bot
Comment 17 2019-03-01 13:33:01 PST
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 18 2019-03-01 13:33:59 PST
Note You need to log in before you can comment on or make changes to this bug.