Bug 8644 - XMLHttpRequest removes spaces from content-types before processing
Summary: XMLHttpRequest removes spaces from content-types before processing
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P4 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
: 8997 (view as bug list)
Depends on:
Blocks: 5954
  Show dependency treegraph
 
Reported: 2006-04-28 03:50 PDT by Eric Seidel (no email)
Modified: 2018-12-10 12:33 PST (History)
11 users (show)

See Also:


Attachments
Patch (5.39 KB, patch)
2018-12-09 02:20 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-sierra (2.53 MB, application/zip)
2018-12-09 03:22 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews107 for mac-sierra-wk2 (3.12 MB, application/zip)
2018-12-09 03:32 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews115 for mac-sierra (2.04 MB, application/zip)
2018-12-09 04:12 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews123 for ios-simulator-wk2 (2.45 MB, application/zip)
2018-12-09 04:16 PST, EWS Watchlist
no flags Details
Patch (10.43 KB, patch)
2018-12-09 05:22 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (10.50 KB, patch)
2018-12-10 00:22 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (10.23 KB, patch)
2018-12-10 10:21 PST, Rob Buis
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2006-04-28 03:50:16 PDT
static inline String getMIMEType(const String& contentTypeString)
in xmlhttprequest.cpp has a line which skips spaces.

I'm not sure this is right.  According to RFC 2045 " " is an invalid char for MIME types, we're just ignoring it, instead of rejeccting the content type as I would have expected.
Comment 1 Alexey Proskuryakov 2006-04-28 09:56:23 PDT
I think skipping spaces accounts for the following (allowed by RFC 2616, if I understand it correctly):

Content-Type: text/html  ;  charset=windows-1251

The existing code certainly seems to be too forgiving. I'm marking this as a blocker for bug 5954 (Cleanup Content-Type parsing).
Comment 2 Dave Hyatt 2006-04-28 11:41:18 PDT
What WinIE does is all that matters.  We may be too forgiving because they are.  Make sure to test with WinIE.
Comment 3 Darin Adler 2006-06-04 16:27:02 PDT
*** Bug 8997 has been marked as a duplicate of this bug. ***
Comment 4 Julian Reschke 2016-09-06 02:11:07 PDT
WFIW, the equivalent bug in Chromium currently is being fixed: https://bugs.chromium.org/p/chromium/issues/detail?id=642346#c11
Comment 5 Rob Buis 2018-12-09 02:20:37 PST
Created attachment 356913 [details]
Patch
Comment 6 EWS Watchlist 2018-12-09 03:22:29 PST
Comment on attachment 356913 [details]
Patch

Attachment 356913 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/10325909

New failing tests:
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.html
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker.html
Comment 7 EWS Watchlist 2018-12-09 03:22:30 PST
Created attachment 356914 [details]
Archive of layout-test-results from ews101 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 8 EWS Watchlist 2018-12-09 03:32:53 PST
Comment on attachment 356913 [details]
Patch

Attachment 356913 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10325922

New failing tests:
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.html
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker.html
Comment 9 EWS Watchlist 2018-12-09 03:32:55 PST
Created attachment 356915 [details]
Archive of layout-test-results from ews107 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 10 EWS Watchlist 2018-12-09 04:12:56 PST
Comment on attachment 356913 [details]
Patch

Attachment 356913 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/10325980

New failing tests:
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.html
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker.html
Comment 11 EWS Watchlist 2018-12-09 04:12:57 PST
Created attachment 356919 [details]
Archive of layout-test-results from ews115 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 12 EWS Watchlist 2018-12-09 04:16:00 PST
Comment on attachment 356913 [details]
Patch

Attachment 356913 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10325979

New failing tests:
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.html
imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker.html
Comment 13 EWS Watchlist 2018-12-09 04:16:02 PST
Created attachment 356920 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 14 Rob Buis 2018-12-09 05:22:43 PST
Created attachment 356921 [details]
Patch
Comment 15 Darin Adler 2018-12-09 17:15:59 PST
Comment on attachment 356921 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=356921&action=review

I’m not sure this does the right thing. I’d like to see perhaps some unit tests for this function. There are some strange edge cases in the function. For example, if the string contains only spaces and tabs then we return all those spaces and tabs, rather than returning the empty string, and FetchResponse::create might want it to return an empty string instead.

> Source/WebCore/platform/network/HTTPParsers.cpp:304
> +    unsigned pos = 0;

If writing new code it would be better to use a word rather than a word fragment. I think "position" would be OK.

> Source/WebCore/platform/network/HTTPParsers.cpp:307
> +    while (pos < length) {

Seems like this can be written as a for loop.

> Source/WebCore/platform/network/HTTPParsers.cpp:320
> +    while (pos < length) {

Seems like this can be written as a for loop.
Comment 16 Rob Buis 2018-12-10 00:22:45 PST
Created attachment 356949 [details]
Patch
Comment 17 Chris Dumez 2018-12-10 08:56:11 PST
Comment on attachment 356949 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=356949&action=review

> Source/WebCore/ChangeLog:10
> +        adheres to LWS definition from RFC 2616, i.e. space or HT.

RFC 2616 is dead, we should stop referring to it. Here, I think we may want https://tools.ietf.org/html/rfc7231#section-3.1.1.1 instead.
Comment 18 Chris Dumez 2018-12-10 09:00:33 PST
Comment on attachment 356949 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=356949&action=review

r=me with comments.

> Source/WebCore/platform/network/HTTPParsers.cpp:328
> +        if (c == ',' || c == ';')

Why is this in the comma section?  ';' is not about allow multiple values. I think we should move the ';'...

> Source/WebCore/platform/network/HTTPParsers.cpp:331
> +        if (c != '\t' && c != ' ')

... to here.
Comment 19 Rob Buis 2018-12-10 09:24:10 PST
(In reply to Chris Dumez from comment #18)
> Comment on attachment 356949 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=356949&action=review
> 
> r=me with comments.
> 
> > Source/WebCore/platform/network/HTTPParsers.cpp:328
> > +        if (c == ',' || c == ';')
> 
> Why is this in the comma section?  ';' is not about allow multiple values. I
> think we should move the ';'...
> 
> > Source/WebCore/platform/network/HTTPParsers.cpp:331
> > +        if (c != '\t' && c != ' ')
> 
> ... to here.

Are you sure about that? The old behavior is to break as soon as ';' is seen (like in chromium). I don't want to change too much except no longer ignoring whitespace, since that may break stuff.
Comment 20 Chris Dumez 2018-12-10 09:34:52 PST
Comment on attachment 356949 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=356949&action=review

>>> Source/WebCore/platform/network/HTTPParsers.cpp:328
>>> +        if (c == ',' || c == ';')
>> 
>> Why is this in the comma section?  ';' is not about allow multiple values. I think we should move the ';'...
> 
> Are you sure about that? The old behavior is to break as soon as ';' is seen (like in chromium). I don't want to change too much except no longer ignoring whitespace, since that may break stuff.

Oh, I guess I am confused about why we're not also breaking as soon as we fine an optional white space (OWS), below.
Comment 21 Chris Dumez 2018-12-10 09:36:26 PST
Comment on attachment 356949 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=356949&action=review

>> Source/WebCore/platform/network/HTTPParsers.cpp:331
>> +        if (c != '\t' && c != ' ')
> 
> ... to here.

I.e. 
if (c == '\t' || c == ' ' || c == ';')
    break;

typeEnd = position + 1;

Am I missing something?
Comment 22 Rob Buis 2018-12-10 10:02:07 PST
(In reply to Chris Dumez from comment #21)
> Comment on attachment 356949 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=356949&action=review
> 
> >> Source/WebCore/platform/network/HTTPParsers.cpp:331
> >> +        if (c != '\t' && c != ' ')
> > 
> > ... to here.
> 
> I.e. 
> if (c == '\t' || c == ' ' || c == ';')
>     break;
> 
> typeEnd = position + 1;
> 
> Am I missing something?

Ah, if that is what you meant I misinterpreted your original suggestion. That does seem  to be valid and more efficient, I'll make a patch.
Comment 23 Rob Buis 2018-12-10 10:21:14 PST
Created attachment 356971 [details]
Patch
Comment 24 WebKit Commit Bot 2018-12-10 12:31:25 PST
Comment on attachment 356971 [details]
Patch

Clearing flags on attachment: 356971

Committed r239040: <https://trac.webkit.org/changeset/239040>
Comment 25 WebKit Commit Bot 2018-12-10 12:31:27 PST
All reviewed patches have been landed.  Closing bug.
Comment 26 Radar WebKit Bug Importer 2018-12-10 12:33:41 PST
<rdar://problem/46604633>