Title: [286061] trunk
Revision
286061
Author
commit-qu...@webkit.org
Date
2021-11-19 07:37:03 -0800 (Fri, 19 Nov 2021)

Log Message

LayoutTests/imported/w3c:
Import css/css-values/urls web-platform-tests
Don't modify fragment-only or empty image URLs
https://bugs.webkit.org/show_bug.cgi?id=229917

Patch by Matt Woodrow <matt.wood...@gmail.com> on 2021-11-19
Reviewed by Darin Adler.

Change handling of empty and fragment url()s for images to not convert to a fully resolved
path, and instead preserve them as-is, to match css-values4 requirements.

Import new tests in css/css-values/urls from 5e3187856a311f583124735cad5a03baa61951b3 and
add expectations for the new tests.

* resources/import-expectations.json:
* web-platform-tests/css/css-values/urls/empty-expected.txt:
* web-platform-tests/css/css-values/urls/empty.html:
* web-platform-tests/css/css-values/urls/fragment-only-expected.txt: Added.
* web-platform-tests/css/css-values/urls/fragment-only.html: Added.
* web-platform-tests/css/css-values/urls/resolve-relative-to-base-expected.txt: Added.
* web-platform-tests/css/css-values/urls/resolve-relative-to-base.html: Added.
* web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet-expected.txt: Added.
* web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html: Added.
* web-platform-tests/css/css-values/urls/support/fragment-only-urls.css: Added.
(:root):
(#external-unquoted):
(#external-quoted):
(#external-variable):
* web-platform-tests/css/css-values/urls/support/relative-urls.css: Added.
(:root):
(#stylesheet-relative-image):
(#stylesheet-relative-variable-image):
(#stylesheet-relative-document-variable-image):
* web-platform-tests/css/css-values/urls/support/w3c-import.log:
* web-platform-tests/css/css-values/urls/w3c-import.log:

Source/WebCore:
Don't modify fragment-only or empty image URLs
https://bugs.webkit.org/show_bug.cgi?id=229917

Patch by Matt Woodrow <matt.wood...@gmail.com> on 2021-11-19
Reviewed by Darin Adler.

Don't modify fragment-only or empty image URLs, as-per css-values-4

Existing web-platform-tests are marked as passing.

* css/CSSImageValue.cpp:
(WebCore::CSSImageValue::reresolvedURL const):
* css/parser/CSSParserContext.cpp:
(WebCore::CSSParserContext::completeURL const):
* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeImage):
* dom/Document.cpp:
(WebCore::Document::completeURL const):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/fast/css/invalid-cursor-property-crash.html (286060 => 286061)


--- trunk/LayoutTests/fast/css/invalid-cursor-property-crash.html	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/fast/css/invalid-cursor-property-crash.html	2021-11-19 15:37:03 UTC (rev 286061)
@@ -7,8 +7,8 @@
             
         var d = document.getElementById('theDiv');
         var style = document.defaultView.getComputedStyle(d, '');
-        
-        if (style && style.cursor == 'url("' + document.location + '"), auto')
+
+        if (style && style.cursor == 'url(""), auto')
             document.getElementById('result').innerHTML = 'SUCCESS';            
     }
     </script>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-11-19 15:37:03 UTC (rev 286061)
@@ -1,3 +1,39 @@
+2021-11-19  Matt Woodrow  <matt.wood...@gmail.com>
+
+        Import css/css-values/urls web-platform-tests
+        Don't modify fragment-only or empty image URLs
+        https://bugs.webkit.org/show_bug.cgi?id=229917
+
+        Reviewed by Darin Adler.
+
+        Change handling of empty and fragment url()s for images to not convert to a fully resolved
+        path, and instead preserve them as-is, to match css-values4 requirements.
+
+        Import new tests in css/css-values/urls from 5e3187856a311f583124735cad5a03baa61951b3 and
+        add expectations for the new tests.
+
+        * resources/import-expectations.json:
+        * web-platform-tests/css/css-values/urls/empty-expected.txt:
+        * web-platform-tests/css/css-values/urls/empty.html:
+        * web-platform-tests/css/css-values/urls/fragment-only-expected.txt: Added.
+        * web-platform-tests/css/css-values/urls/fragment-only.html: Added.
+        * web-platform-tests/css/css-values/urls/resolve-relative-to-base-expected.txt: Added.
+        * web-platform-tests/css/css-values/urls/resolve-relative-to-base.html: Added.
+        * web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet-expected.txt: Added.
+        * web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html: Added.
+        * web-platform-tests/css/css-values/urls/support/fragment-only-urls.css: Added.
+        (:root):
+        (#external-unquoted):
+        (#external-quoted):
+        (#external-variable):
+        * web-platform-tests/css/css-values/urls/support/relative-urls.css: Added.
+        (:root):
+        (#stylesheet-relative-image):
+        (#stylesheet-relative-variable-image):
+        (#stylesheet-relative-document-variable-image):
+        * web-platform-tests/css/css-values/urls/support/w3c-import.log:
+        * web-platform-tests/css/css-values/urls/w3c-import.log:
+
 2021-11-18  Ben Nham  <n...@apple.com>
 
         Add support for onpushsubscriptionchange event handler

Modified: trunk/LayoutTests/imported/w3c/resources/import-expectations.json (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2021-11-19 15:37:03 UTC (rev 286061)
@@ -144,6 +144,7 @@
     "web-platform-tests/css/css-transforms/": "import", 
     "web-platform-tests/css/css-transitions": "import", 
     "web-platform-tests/css/css-ui": "import", 
+    "web-platform-tests/css/css-values/urls": "import", 
     "web-platform-tests/css/css-variables": "import", 
     "web-platform-tests/css/css-will-change": "import", 
     "web-platform-tests/css/css-writing-modes": "import", 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/empty.html (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/empty.html	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/empty.html	2021-11-19 15:37:03 UTC (rev 286061)
@@ -7,10 +7,12 @@
 <style>
 #inline-unquoted {
     background-image: url();
+    cursor: url(), pointer;
 }
 
 #inline-quoted {
     background-image: url("");
+    cursor: url(""), pointer;
 }
 </style>
 <link rel=stylesheet href=""
@@ -26,15 +28,12 @@
   "external-quoted"
 ];
 
-const inline_url = location.href;
-const external_url = new URL(document.querySelector("link[rel=stylesheet]").href, location.href).href;
-
 for (let id of ids) {
     test(function() {
         const el = document.getElementById(id);
-        const expected = id.startsWith("inline-") ? inline_url : external_url;
         const style = window.getComputedStyle(el);
-        assert_equals(style["background-image"], 'url("' + expected + '")');
+        assert_equals(style["background-image"], 'url("")');
+        assert_equals(style["cursor"], 'url(""), pointer');
     }, "empty URL: " + id);
 }
 </script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only-expected.txt (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only-expected.txt	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,7 @@
+
+PASS empty URL: inline-unquoted
+PASS empty URL: inline-quoted
+PASS empty URL: external-unquoted
+PASS empty URL: external-quoted
+PASS empty URL: external-variable
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only.html (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only.html	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,40 @@
+<!doctype html>
+<title>Fragment-on URLs behaviour</title>
+<link rel=help href=""
+<script src=""
+<script src=""
+<style>
+#inline-unquoted {
+    background-image: url(#foo);
+    cursor: url(#foo), pointer;
+}
+
+#inline-quoted {
+    background-image: url("#foo");
+    cursor: url("#foo"), pointer;
+}
+</style>
+<link rel=stylesheet href=""
+<div id="inline-unquoted"></div>
+<div id="inline-quoted"></div>
+<div id="external-unquoted"></div>
+<div id="external-quoted"></div>
+<div id="external-variable"></div>
+<script>
+const ids = [
+  "inline-unquoted",
+  "inline-quoted",
+  "external-unquoted",
+  "external-quoted",
+  "external-variable",
+];
+
+for (let id of ids) {
+    test(function() {
+        const el = document.getElementById(id);
+        const style = window.getComputedStyle(el);
+        assert_equals(style["background-image"], 'url("#foo")');
+        assert_equals(style["cursor"], 'url("#foo"), pointer');
+    }, "empty URL: " + id);
+}
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base-expected.txt (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base-expected.txt	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,4 @@
+
+FAIL base-relative URL: relative-image-url Type error
+FAIL base-relative URL: relative-image-variable-url Type error
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base.html (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base.html	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,35 @@
+<!doctype html>
+<title>URLs in embedded style sheets resolve relative to the document base URI</title>
+<link rel=help href=""
+<script src=""
+<script src=""
+<base href=""
+<style>
+:root {
+    --image-path: url("images/test.png");
+}
+#relative-image-url {
+    background-image: url(images/test.png);
+}
+
+#relative-image-variable-url {
+    background-image: var(--image-path);
+}
+</style>
+<div id="relative-image-url"></div>
+<div id="relative-image-variable-url"></div>
+<script>
+const ids = [
+  "relative-image-url",
+  "relative-image-variable-url"
+];
+
+for (let id of ids) {
+    test(() => {
+        const el = document.getElementById(id);
+        const backgroundImageStyle = window.getComputedStyle(el)["background-image"];
+        const baseRelativeImageURL = new URL("images/test.png", document.baseURI);
+        assert_equals(backgroundImageStyle, `url("${baseRelativeImageURL.href}")`);
+    }, "base-relative URL: " + id);
+}
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet-expected.txt (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet-expected.txt	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,5 @@
+
+PASS stylesheet-relative URL: stylesheet-relative-image
+PASS stylesheet-relative URL: stylesheet-relative-variable-image
+PASS stylesheet-relative URL: stylesheet-relative-document-variable-image
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,33 @@
+<!doctype html>
+<title>URLs in a stylesheet resolve relative to the stylesheet</title>
+<link rel=help href=""
+<script src=""
+<script src=""
+<link id="stylesheet" rel=stylesheet href=""
+<div id="stylesheet-relative-image"></div>
+<div id="stylesheet-relative-variable-image"></div>
+<div id="stylesheet-relative-document-variable-image"></div>
+<style>
+    :root {
+        --image-path-document: url("images/test.png");
+    }
+</style>
+<script>
+const ids = [
+  "stylesheet-relative-image",
+  "stylesheet-relative-variable-image",
+  "stylesheet-relative-document-variable-image",
+];
+
+for (let id of ids) {
+    test(() => {
+        const el = document.getElementById(id);
+        const backgroundImageStyle = window.getComputedStyle(el)["background-image"];
+
+        const stylesheet = document.getElementById("stylesheet");
+        const sheetRelativeImageURL = new URL("images/test.png", stylesheet.href);
+
+        assert_equals(backgroundImageStyle, `url("${sheetRelativeImageURL.href}")`);
+    }, "stylesheet-relative URL: " + id);
+}
+</script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/empty-urls.css (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/empty-urls.css	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/empty-urls.css	2021-11-19 15:37:03 UTC (rev 286061)
@@ -1,7 +1,9 @@
 #external-unquoted {
     background-image: url();
+    cursor: url(), pointer;
 }
 
 #external-quoted {
     background-image: url("");
+    cursor: url(""), pointer;
 }

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/fragment-only-urls.css (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/fragment-only-urls.css	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/fragment-only-urls.css	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,19 @@
+:root {
+    --fragment-image-url: url("#foo");
+    --fragment-cursor-url: url("#foo"), pointer;
+}
+
+#external-unquoted {
+    background-image: url(#foo);
+    cursor: url(#foo), pointer;
+}
+
+#external-quoted {
+    background-image: url("#foo");
+    cursor: url("#foo"), pointer;
+}
+
+#external-variable {
+    background-image: var(--fragment-image-url);
+    cursor: var(--fragment-cursor-url);
+}

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/relative-urls.css (0 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/relative-urls.css	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/relative-urls.css	2021-11-19 15:37:03 UTC (rev 286061)
@@ -0,0 +1,15 @@
+:root {
+    --image-path-stylesheet: url("images/test.png");
+}
+
+#stylesheet-relative-image {
+    background-image: url(images/test.png);
+}
+
+#stylesheet-relative-variable-image {
+    background-image: var(--image-path-stylesheet);
+}
+
+#stylesheet-relative-document-variable-image {
+    background-image: var(--image-path-document);
+}

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/w3c-import.log (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/w3c-import.log	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/w3c-import.log	2021-11-19 15:37:03 UTC (rev 286061)
@@ -15,3 +15,5 @@
 ------------------------------------------------------------------------
 List of files:
 /LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/empty-urls.css
+/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/fragment-only-urls.css
+/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/support/relative-urls.css

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/w3c-import.log (286060 => 286061)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/w3c-import.log	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/w3c-import.log	2021-11-19 15:37:03 UTC (rev 286061)
@@ -15,3 +15,6 @@
 ------------------------------------------------------------------------
 List of files:
 /LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/empty.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/fragment-only.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-base.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-values/urls/resolve-relative-to-stylesheet.html

Modified: trunk/Source/WebCore/ChangeLog (286060 => 286061)


--- trunk/Source/WebCore/ChangeLog	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/ChangeLog	2021-11-19 15:37:03 UTC (rev 286061)
@@ -1,3 +1,23 @@
+2021-11-19  Matt Woodrow  <matt.wood...@gmail.com>
+
+        Don't modify fragment-only or empty image URLs
+        https://bugs.webkit.org/show_bug.cgi?id=229917
+
+        Reviewed by Darin Adler.
+
+        Don't modify fragment-only or empty image URLs, as-per css-values-4
+
+        Existing web-platform-tests are marked as passing.
+
+        * css/CSSImageValue.cpp:
+        (WebCore::CSSImageValue::reresolvedURL const):
+        * css/parser/CSSParserContext.cpp:
+        (WebCore::CSSParserContext::completeURL const):
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::consumeImage):
+        * dom/Document.cpp:
+        (WebCore::Document::completeURL const):
+
 2021-11-19  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK][a11y] Add implementation of document interface when building with ATSPI

Modified: trunk/Source/WebCore/css/CSSImageValue.cpp (286060 => 286061)


--- trunk/Source/WebCore/css/CSSImageValue.cpp	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/css/CSSImageValue.cpp	2021-11-19 15:37:03 UTC (rev 286061)
@@ -84,6 +84,9 @@
 
 URL CSSImageValue::reresolvedURL(const Document& document) const
 {
+    if (isCSSLocalURL(m_location.resolvedURL.string()))
+        return m_location.resolvedURL;
+
     // Re-resolving the URL is important for cases where resolvedURL is still not an absolute URL.
     // This can happen if there was no absolute base URL when the value was created, like a style from a document without a base URL.
     return document.completeURL(m_location.resolvedURL.string());

Modified: trunk/Source/WebCore/css/CSSValue.cpp (286060 => 286061)


--- trunk/Source/WebCore/css/CSSValue.cpp	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/css/CSSValue.cpp	2021-11-19 15:37:03 UTC (rev 286061)
@@ -232,6 +232,11 @@
     return false;
 }
 
+bool CSSValue::isCSSLocalURL(StringView relativeURL)
+{
+    return relativeURL.isEmpty() || relativeURL.startsWith('#');
+}
+
 String CSSValue::cssText() const
 {
     switch (classType()) {

Modified: trunk/Source/WebCore/css/CSSValue.h (286060 => 286061)


--- trunk/Source/WebCore/css/CSSValue.h	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/css/CSSValue.h	2021-11-19 15:37:03 UTC (rev 286061)
@@ -155,6 +155,10 @@
     bool equals(const CSSValue&) const;
     bool operator==(const CSSValue& other) const { return equals(other); }
 
+    // https://www.w3.org/TR/css-values-4/#local-urls
+    // Empty URLs and fragment-only URLs should not be resolved relative to the base URL.
+    static bool isCSSLocalURL(StringView relativeURL);
+
 protected:
 
     static const size_t ClassTypeBits = 6;

Modified: trunk/Source/WebCore/css/parser/CSSParserContext.cpp (286060 => 286061)


--- trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2021-11-19 15:37:03 UTC (rev 286061)
@@ -245,8 +245,13 @@
 ResolvedURL CSSParserContext::completeURL(const String& string) const
 {
     auto result = [&] () -> ResolvedURL {
+        // See also Document::completeURL(const String&)
         if (string.isNull())
             return { };
+
+        if (CSSValue::isCSSLocalURL(string))
+            return { string, { URL(), string } };
+
         if (charset.isEmpty())
             return { string, { baseURL, string } };
         auto encodingForURLParsing = TextEncoding { charset }.encodingForFormSubmissionOrURLParsing();

Modified: trunk/Source/WebCore/dom/Document.cpp (286060 => 286061)


--- trunk/Source/WebCore/dom/Document.cpp	2021-11-19 15:01:50 UTC (rev 286060)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-11-19 15:37:03 UTC (rev 286061)
@@ -5591,11 +5591,13 @@
 
 URL Document::completeURL(const String& url, const URL& baseURLOverride, ForceUTF8 forceUTF8) const
 {
+    // See also CSSParserContext::completeURL(const String&)
+
     // Always return a null URL when passed a null string.
     // FIXME: Should we change the URL constructor to have this behavior?
-    // See also [CSS]StyleSheet::completeURL(const String&)
     if (url.isNull())
         return URL();
+
     const URL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == aboutBlankURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride;
     if (!m_decoder || forceUTF8 == ForceUTF8::Yes)
         return URL(baseURL, url);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to