Title: [238124] trunk
Revision
238124
Author
commit-qu...@webkit.org
Date
2018-11-12 23:35:41 -0800 (Mon, 12 Nov 2018)

Log Message

Content-Type parameter values should allow empty quoted strings
https://bugs.webkit.org/show_bug.cgi?id=191388

Patch by Rob Buis <rb...@igalia.com> on 2018-11-12
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Include improved expected test result and updated mime-type test:
https://github.com/whatwg/mimesniff/pull/79

* web-platform-tests/mimesniff/mime-types/charset-parameter.window-expected.txt:
* web-platform-tests/mimesniff/mime-types/parsing.any-expected.txt:
* web-platform-tests/mimesniff/mime-types/parsing.any.worker-expected.txt:
* web-platform-tests/mimesniff/mime-types/resources/mime-types.json:
* web-platform-tests/xhr/overridemimetype-blob-expected.txt:

Source/WebCore:

According to RFC 2045 and https://mimesniff.spec.whatwg.org/#parsing-a-mime-type empty
quoted strings are acceptable for Content-Type parameter values. They
are accepted by Firefox and Chrome implementations as well.

Test: web-platform-tests/xhr/overridemimetype-blob.html

* platform/network/ParsedContentType.cpp:
(WebCore::parseToken):
(WebCore::parseQuotedString):
(WebCore::parseContentType):
* platform/network/ParsedContentType.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-11-13 07:35:41 UTC (rev 238124)
@@ -1,3 +1,19 @@
+2018-11-12  Rob Buis  <rb...@igalia.com>
+
+        Content-Type parameter values should allow empty quoted strings
+        https://bugs.webkit.org/show_bug.cgi?id=191388
+
+        Reviewed by Dean Jackson.
+
+        Include improved expected test result and updated mime-type test:
+        https://github.com/whatwg/mimesniff/pull/79
+
+        * web-platform-tests/mimesniff/mime-types/charset-parameter.window-expected.txt:
+        * web-platform-tests/mimesniff/mime-types/parsing.any-expected.txt:
+        * web-platform-tests/mimesniff/mime-types/parsing.any.worker-expected.txt:
+        * web-platform-tests/mimesniff/mime-types/resources/mime-types.json:
+        * web-platform-tests/xhr/overridemimetype-blob-expected.txt:
+
 2018-11-12  Sihui Liu  <sihui_...@apple.com>
 
         imported/w3c/web-platform-tests/IndexedDB/keygenerator-explicit.html crashing on iOS device

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/charset-parameter.window-expected.txt (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/charset-parameter.window-expected.txt	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/charset-parameter.window-expected.txt	2018-11-13 07:35:41 UTC (rev 238124)
@@ -31,7 +31,7 @@
 FAIL text/html;charset="\ gbk" assert_equals: expected "GBK" but got "UTF-8"
 FAIL text/html;charset="\g\b\k" assert_equals: expected "GBK" but got "UTF-8"
 FAIL text/html;charset="gbk"x assert_equals: expected "GBK" but got "UTF-8"
-FAIL text/html;charset="";charset=GBK assert_equals: expected "GBK" but got "UTF-8"
+PASS text/html;charset="";charset=GBK 
 PASS text/html;charset=";charset=GBK 
 PASS text/html;charset={gbk} 
 PASS text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any-expected.txt (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any-expected.txt	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any-expected.txt	2018-11-13 07:35:41 UTC (rev 238124)
@@ -62,8 +62,8 @@
 FAIL text/html;charset="\g\b\k" (Request/Response) assert_equals: expected "text/html;charset=gbk" but got "text/html"
 FAIL text/html;charset="gbk"x (Blob/File) assert_equals: Blob expected "text/html;charset=gbk" but got "text/html;charset=\"gbk\"x"
 FAIL text/html;charset="gbk"x (Request/Response) assert_equals: expected "text/html;charset=gbk" but got "text/html"
-FAIL text/html;charset="";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=GBK" but got "text/html;charset=\"\";charset=gbk"
-FAIL text/html;charset="";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=GBK" but got "text/html"
+FAIL text/html;charset="";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=\"\"" but got "text/html;charset=\"\";charset=gbk"
+FAIL text/html;charset="";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=\"\"" but got "text/html"
 FAIL text/html;charset=";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=\";charset=GBK\"" but got "text/html;charset=\";charset=gbk"
 FAIL text/html;charset=";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=\";charset=GBK\"" but got "text/html"
 FAIL text/html;charset={gbk} (Blob/File) assert_equals: Blob expected "text/html;charset=\"{gbk}\"" but got "text/html;charset={gbk}"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker-expected.txt (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker-expected.txt	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/parsing.any.worker-expected.txt	2018-11-13 07:35:41 UTC (rev 238124)
@@ -62,8 +62,8 @@
 FAIL text/html;charset="\g\b\k" (Request/Response) assert_equals: expected "text/html;charset=gbk" but got "text/html"
 FAIL text/html;charset="gbk"x (Blob/File) assert_equals: Blob expected "text/html;charset=gbk" but got "text/html;charset=\"gbk\"x"
 FAIL text/html;charset="gbk"x (Request/Response) assert_equals: expected "text/html;charset=gbk" but got "text/html"
-FAIL text/html;charset="";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=GBK" but got "text/html;charset=\"\";charset=gbk"
-FAIL text/html;charset="";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=GBK" but got "text/html"
+FAIL text/html;charset="";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=\"\"" but got "text/html;charset=\"\";charset=gbk"
+FAIL text/html;charset="";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=\"\"" but got "text/html"
 FAIL text/html;charset=";charset=GBK (Blob/File) assert_equals: Blob expected "text/html;charset=\";charset=GBK\"" but got "text/html;charset=\";charset=gbk"
 FAIL text/html;charset=";charset=GBK (Request/Response) assert_equals: expected "text/html;charset=\";charset=GBK\"" but got "text/html"
 FAIL text/html;charset={gbk} (Blob/File) assert_equals: Blob expected "text/html;charset=\"{gbk}\"" but got "text/html;charset={gbk}"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/resources/mime-types.json (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/resources/mime-types.json	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/mimesniff/mime-types/resources/mime-types.json	2018-11-13 07:35:41 UTC (rev 238124)
@@ -194,9 +194,9 @@
   },
   {
     "input": "text/html;charset=\"\";charset=GBK",
-    "output": "text/html;charset=GBK",
+    "output": "text/html;charset=\"\"",
     "navigable": true,
-    "encoding": "GBK"
+    "encoding": null
   },
   {
     "input": "text/html;charset=\";charset=GBK",

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt (238123 => 238124)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt	2018-11-13 07:35:41 UTC (rev 238124)
@@ -33,7 +33,7 @@
 FAIL 29) MIME types need to be parsed and serialized: text/html;charset="\ gbk" assert_equals: expected "text/html;charset=\" gbk\"" but got "text/html"
 FAIL 30) MIME types need to be parsed and serialized: text/html;charset="\g\b\k" assert_equals: expected "text/html;charset=gbk" but got "text/html"
 FAIL 31) MIME types need to be parsed and serialized: text/html;charset="gbk"x assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream"
-FAIL 32) MIME types need to be parsed and serialized: text/html;charset="";charset=GBK assert_equals: expected "text/html;charset=GBK" but got "application/octet-stream"
+FAIL 32) MIME types need to be parsed and serialized: text/html;charset="";charset=GBK assert_equals: expected "text/html;charset=\"\"" but got "text/html"
 FAIL 33) MIME types need to be parsed and serialized: text/html;charset=";charset=GBK assert_equals: expected "text/html;charset=\";charset=GBK\"" but got "application/octet-stream"
 FAIL 34) MIME types need to be parsed and serialized: text/html;charset={gbk} assert_equals: expected "text/html;charset=\"{gbk}\"" but got "text/html"
 FAIL 35) MIME types need to be parsed and serialized: text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk assert_equals: expected "text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk" but got "text/html"

Modified: trunk/Source/WebCore/ChangeLog (238123 => 238124)


--- trunk/Source/WebCore/ChangeLog	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/Source/WebCore/ChangeLog	2018-11-13 07:35:41 UTC (rev 238124)
@@ -1,3 +1,22 @@
+2018-11-12  Rob Buis  <rb...@igalia.com>
+
+        Content-Type parameter values should allow empty quoted strings
+        https://bugs.webkit.org/show_bug.cgi?id=191388
+
+        Reviewed by Dean Jackson.
+
+        According to RFC 2045 and https://mimesniff.spec.whatwg.org/#parsing-a-mime-type empty
+        quoted strings are acceptable for Content-Type parameter values. They
+        are accepted by Firefox and Chrome implementations as well.
+
+        Test: web-platform-tests/xhr/overridemimetype-blob.html
+
+        * platform/network/ParsedContentType.cpp:
+        (WebCore::parseToken):
+        (WebCore::parseQuotedString):
+        (WebCore::parseContentType):
+        * platform/network/ParsedContentType.h:
+
 2018-11-12  Christopher Reid  <chris.r...@sony.com>
 
         [Curl] Reject entire cookie if the domain fails a tailmatch.

Modified: trunk/Source/WebCore/platform/network/ParsedContentType.cpp (238123 => 238124)


--- trunk/Source/WebCore/platform/network/ParsedContentType.cpp	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.cpp	2018-11-13 07:35:41 UTC (rev 238124)
@@ -53,7 +53,7 @@
     return isASCII(c) && c > ' ' && c != '"' && c != '(' && c != ')' && c != ',' && c != '/' && (c < ':' || c > '@') && (c < '[' || c > ']');
 }
 
-static SubstringRange parseToken(const String& input, unsigned& startIndex)
+static std::optional<SubstringRange> parseToken(const String& input, unsigned& startIndex)
 {
     unsigned inputLength = input.length();
     unsigned tokenStart = startIndex;
@@ -60,18 +60,20 @@
     unsigned& tokenEnd = startIndex;
 
     if (tokenEnd >= inputLength)
-        return SubstringRange();
+        return std::nullopt;
 
     while (tokenEnd < inputLength) {
         if (!isTokenCharacter(input[tokenEnd]))
-            return SubstringRange(tokenStart, tokenEnd - tokenStart);
+            break;
         ++tokenEnd;
     }
 
+    if (tokenEnd == tokenStart)
+        return std::nullopt;
     return SubstringRange(tokenStart, tokenEnd - tokenStart);
 }
 
-static SubstringRange parseQuotedString(const String& input, unsigned& startIndex)
+static std::optional<SubstringRange> parseQuotedString(const String& input, unsigned& startIndex)
 {
     unsigned inputLength = input.length();
     unsigned quotedStringStart = startIndex + 1;
@@ -78,16 +80,16 @@
     unsigned& quotedStringEnd = startIndex;
 
     if (quotedStringEnd >= inputLength)
-        return SubstringRange();
+        return std::nullopt;
 
     if (input[quotedStringEnd++] != '"' || quotedStringEnd >= inputLength)
-        return SubstringRange();
+        return std::nullopt;
 
     bool lastCharacterWasBackslash = false;
     char currentCharacter;
     while ((currentCharacter = input[quotedStringEnd++]) != '"' || lastCharacterWasBackslash) {
         if (quotedStringEnd >= inputLength)
-            return SubstringRange();
+            return std::nullopt;
         if (currentCharacter == '\\' && !lastCharacterWasBackslash) {
             lastCharacterWasBackslash = true;
             continue;
@@ -162,7 +164,7 @@
 
     unsigned contentTypeStart = index;
     auto typeRange = parseToken(contentType, index);
-    if (!typeRange.second) {
+    if (!typeRange) {
         LOG_ERROR("Invalid Content-Type, invalid type value.");
         return false;
     }
@@ -173,7 +175,7 @@
     }
 
     auto subTypeRange = parseToken(contentType, index);
-    if (!subTypeRange.second) {
+    if (!subTypeRange) {
         LOG_ERROR("Invalid Content-Type, invalid subtype value.");
         return false;
     }
@@ -189,8 +191,8 @@
     index = semiColonIndex + 1;
     while (true) {
         skipSpaces(contentType, index);
-        SubstringRange keyRange = parseToken(contentType, index);
-        if (!keyRange.second || index >= contentTypeLength) {
+        auto keyRange = parseToken(contentType, index);
+        if (!keyRange || index >= contentTypeLength) {
             LOG_ERROR("Invalid Content-Type parameter name.");
             return false;
         }
@@ -203,13 +205,13 @@
 
         // Should we tolerate spaces here?
         String value;
-        SubstringRange valueRange;
+        std::optional<SubstringRange> valueRange;
         if (contentType[index] == '"')
             valueRange = parseQuotedString(contentType, index);
         else
             valueRange = parseToken(contentType, index);
 
-        if (!valueRange.second) {
+        if (!valueRange) {
             LOG_ERROR("Invalid Content-Type, invalid parameter value.");
             return false;
         }
@@ -220,7 +222,7 @@
             return false;
         }
 
-        receiver.setContentTypeParameter(keyRange, valueRange);
+        receiver.setContentTypeParameter(*keyRange, *valueRange);
 
         if (index >= contentTypeLength)
             return true;

Modified: trunk/Source/WebCore/platform/network/ParsedContentType.h (238123 => 238124)


--- trunk/Source/WebCore/platform/network/ParsedContentType.h	2018-11-13 07:21:11 UTC (rev 238123)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.h	2018-11-13 07:35:41 UTC (rev 238124)
@@ -29,8 +29,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ParsedContentType_h
-#define ParsedContentType_h
+#pragma once
 
 #include <wtf/HashMap.h>
 #include <wtf/text/StringHash.h>
@@ -66,5 +65,3 @@
 };
 
 }
-
-#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to