Skip to content

Commit

Permalink
Correct URL encoding of CSS
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261079
rdar://114889625

Reviewed by Tim Nguyen.

CSS invokes the URL parser normally and therefore always uses UTF-8 as
its URL encoding: https://drafts.csswg.org/css-values/#url-processing.

This aligns us with the standard and Gecko.

* LayoutTests/http/tests/webarchive/test-css-url-encoding-expected.webarchive:
* LayoutTests/http/tests/webarchive/test-css-url-encoding-shift-jis-expected.webarchive:
* LayoutTests/http/tests/webarchive/test-css-url-encoding-utf-8-expected.webarchive:
* LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/utf-8_include=css-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/windows-1251_include=css-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252_include=css-expected.txt:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::CSSParserContext::completeURL const):

Canonical link: https://commits.webkit.org/270169@main
  • Loading branch information
annevk committed Nov 3, 2023
1 parent 2d7df2a commit c195704
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Webarchive fails to save images referenced in CSS</a>
<key>MIMEType</key>
<string>image/gif</string>
<key>URL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%CB%86%C5%B8</string>
<key>allHeaderFields</key>
<dict>
<key>Accept-Ranges</key>
Expand All @@ -111,7 +111,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<integer>200</integer>
</dict>
<key>WebResourceURL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%CB%86%C5%B8</string>
</dict>
<dict>
<key>WebResourceData</key>
Expand Down Expand Up @@ -162,7 +162,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<key>MIMEType</key>
<string>image/gif</string>
<key>URL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
<key>allHeaderFields</key>
<dict>
<key>Accept-Ranges</key>
Expand All @@ -186,7 +186,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<integer>200</integer>
</dict>
<key>WebResourceURL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
</dict>
<dict>
<key>WebResourceData</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<key>MIMEType</key>
<string>image/gif</string>
<key>URL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%E4%BA%9C</string>
<key>allHeaderFields</key>
<dict>
<key>Accept-Ranges</key>
Expand All @@ -113,7 +113,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<integer>200</integer>
</dict>
<key>WebResourceURL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-no-charset-%E4%BA%9C</string>
</dict>
<dict>
<key>WebResourceData</key>
Expand Down Expand Up @@ -164,7 +164,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<key>MIMEType</key>
<string>image/gif</string>
<key>URL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
<key>allHeaderFields</key>
<dict>
<key>Accept-Ranges</key>
Expand All @@ -188,7 +188,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<integer>200</integer>
</dict>
<key>WebResourceURL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
</dict>
<dict>
<key>WebResourceData</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<key>MIMEType</key>
<string>image/gif</string>
<key>URL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
<key>allHeaderFields</key>
<dict>
<key>Accept-Ranges</key>
Expand All @@ -188,7 +188,7 @@ Webarchive fails to save images referenced in CSS&lt;/a&gt;
<integer>200</integer>
</dict>
<key>WebResourceURL</key>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%88%9F</string>
<string>http://127.0.0.1:8000/webarchive/resources/apple.gif?css-url-shift-jis-%E4%BA%9C</string>
</dict>
<dict>
<key>WebResourceData</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

PASS CSS <link> (utf-8) #<id> { background-image:<url> }
FAIL CSS <link> (windows-1252) #<id> { background-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { background-image:<url> }
PASS CSS <style> #<id> { background-image:<url> }
PASS CSS <link> (utf-8) #<id> { border-image-source:<url> }
FAIL CSS <link> (windows-1252) #<id> { border-image-source:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { border-image-source:<url> }
PASS CSS <style> #<id> { border-image-source:<url> }
PASS CSS <link> (utf-8) #<id>::before { content:<url> }
FAIL CSS <link> (windows-1252) #<id>::before { content:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id>::before { content:<url> }
PASS CSS <style> #<id>::before { content:<url> }
PASS CSS <link> (utf-8) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
FAIL CSS <link> (windows-1252) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <style> @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <link> (utf-8) #<id> { display:list-item; list-style-image:<url> }
FAIL CSS <link> (windows-1252) #<id> { display:list-item; list-style-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { display:list-item; list-style-image:<url> }
PASS CSS <style> #<id> { display:list-item; list-style-image:<url> }
PASS CSS <link> (utf-8) @import <url>;
PASS CSS <link> (windows-1252) @import <url>;
PASS CSS <style> @import <url>;
PASS CSS <link> (utf-8) #<id> { cursor:<url>, pointer }
FAIL CSS <link> (windows-1252) #<id> { cursor:<url>, pointer } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { cursor:<url>, pointer }
PASS CSS <style> #<id> { cursor:<url>, pointer }

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

FAIL CSS <link> (windows-1251) #<id> { background-image:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <link> (windows-1251) #<id> { background-image:<url> }
PASS CSS <link> (utf-8) #<id> { background-image:<url> }
FAIL CSS <style> #<id> { background-image:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
FAIL CSS <link> (windows-1251) #<id> { border-image-source:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> #<id> { background-image:<url> }
PASS CSS <link> (windows-1251) #<id> { border-image-source:<url> }
PASS CSS <link> (utf-8) #<id> { border-image-source:<url> }
FAIL CSS <style> #<id> { border-image-source:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
FAIL CSS <link> (windows-1251) #<id>::before { content:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> #<id> { border-image-source:<url> }
PASS CSS <link> (windows-1251) #<id>::before { content:<url> }
PASS CSS <link> (utf-8) #<id>::before { content:<url> }
FAIL CSS <style> #<id>::before { content:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
FAIL CSS <link> (windows-1251) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> #<id>::before { content:<url> }
PASS CSS <link> (windows-1251) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <link> (utf-8) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
FAIL CSS <style> @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
FAIL CSS <link> (windows-1251) #<id> { display:list-item; list-style-image:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <link> (windows-1251) #<id> { display:list-item; list-style-image:<url> }
PASS CSS <link> (utf-8) #<id> { display:list-item; list-style-image:<url> }
FAIL CSS <style> #<id> { display:list-item; list-style-image:<url> } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> #<id> { display:list-item; list-style-image:<url> }
PASS CSS <link> (windows-1251) @import <url>;
PASS CSS <link> (utf-8) @import <url>;
PASS CSS <style> @import <url>;
FAIL CSS <link> (windows-1251) #<id> { cursor:<url>, pointer } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <link> (windows-1251) #<id> { cursor:<url>, pointer }
PASS CSS <link> (utf-8) #<id> { cursor:<url>, pointer }
FAIL CSS <style> #<id> { cursor:<url>, pointer } assert_equals: expected "%C3%A5" but got "%26%23229%3B"
PASS CSS <style> #<id> { cursor:<url>, pointer }

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

FAIL CSS <link> (windows-1252) #<id> { background-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { background-image:<url> }
PASS CSS <link> (utf-8) #<id> { background-image:<url> }
FAIL CSS <style> #<id> { background-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
FAIL CSS <link> (windows-1252) #<id> { border-image-source:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> #<id> { background-image:<url> }
PASS CSS <link> (windows-1252) #<id> { border-image-source:<url> }
PASS CSS <link> (utf-8) #<id> { border-image-source:<url> }
FAIL CSS <style> #<id> { border-image-source:<url> } assert_equals: expected "%C3%A5" but got "%E5"
FAIL CSS <link> (windows-1252) #<id>::before { content:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> #<id> { border-image-source:<url> }
PASS CSS <link> (windows-1252) #<id>::before { content:<url> }
PASS CSS <link> (utf-8) #<id>::before { content:<url> }
FAIL CSS <style> #<id>::before { content:<url> } assert_equals: expected "%C3%A5" but got "%E5"
FAIL CSS <link> (windows-1252) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> #<id>::before { content:<url> }
PASS CSS <link> (windows-1252) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <link> (utf-8) @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
FAIL CSS <style> @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> } assert_equals: expected "%C3%A5" but got "%E5"
FAIL CSS <link> (windows-1252) #<id> { display:list-item; list-style-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> @font-face { font-family:<id>; src:<url> } #<id> { font-family:<id> }
PASS CSS <link> (windows-1252) #<id> { display:list-item; list-style-image:<url> }
PASS CSS <link> (utf-8) #<id> { display:list-item; list-style-image:<url> }
FAIL CSS <style> #<id> { display:list-item; list-style-image:<url> } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> #<id> { display:list-item; list-style-image:<url> }
PASS CSS <link> (windows-1252) @import <url>;
PASS CSS <link> (utf-8) @import <url>;
PASS CSS <style> @import <url>;
FAIL CSS <link> (windows-1252) #<id> { cursor:<url>, pointer } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <link> (windows-1252) #<id> { cursor:<url>, pointer }
PASS CSS <link> (utf-8) #<id> { cursor:<url>, pointer }
FAIL CSS <style> #<id> { cursor:<url>, pointer } assert_equals: expected "%C3%A5" but got "%E5"
PASS CSS <style> #<id> { cursor:<url>, pointer }

7 changes: 2 additions & 5 deletions Source/WebCore/css/parser/CSSParserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,14 @@ void add(Hasher& hasher, const CSSParserContext& context)
ResolvedURL CSSParserContext::completeURL(const String& string) const
{
auto result = [&] () -> ResolvedURL {
// See also Document::completeURL(const String&)
// See also Document::completeURL(const String&), but note that CSS always uses UTF-8 for URLs
if (string.isNull())
return { };

if (CSSValue::isCSSLocalURL(string))
return { string, URL { string } };

if (charset.isEmpty())
return { string, { baseURL, string } };
auto encodingForURLParsing = PAL::TextEncoding { charset }.encodingForFormSubmissionOrURLParsing();
return { string, { baseURL, string, encodingForURLParsing == PAL::UTF8Encoding() ? nullptr : &encodingForURLParsing } };
return { string, { baseURL, string } };
}();

if (mode == WebVTTMode && !result.resolvedURL.protocolIsData())
Expand Down

0 comments on commit c195704

Please sign in to comment.