Title: [282415] trunk
Revision
282415
Author
[email protected]
Date
2021-09-14 15:19:41 -0700 (Tue, 14 Sep 2021)

Log Message

CSSFontFaceSrcValue.cssText should be quoted consistently with other browsers
https://bugs.webkit.org/show_bug.cgi?id=230273
<rdar://problem/79644124>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

This is being upstreamed in https://github.com/web-platform-tests/wpt/pull/30784.

* web-platform-tests/css/css-fonts/font-family-src-quoted-expected.txt: Added.
* web-platform-tests/css/css-fonts/font-family-src-quoted.html: Added.
* web-platform-tests/css/cssom/cssom-fontfacerule-expected.txt:

Source/WebCore:

In a src: line like "src: local(foobar)", Firefox and Chrome will both quote
"foobar" when reading out of the OM. Same thing with "src: url(foobar)".
We should match them.

Test: imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted.html

* css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcValue::customCSSText const):
* css/CSSMarkup.cpp:
(WebCore::serializeIdentifier):
(WebCore::serializeString):

Source/WTF:

* wtf/unicode/CharacterNames.h:

LayoutTests:

* fast/css/font-face-src-parsing-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282414 => 282415)


--- trunk/LayoutTests/ChangeLog	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/LayoutTests/ChangeLog	2021-09-14 22:19:41 UTC (rev 282415)
@@ -1,3 +1,13 @@
+2021-09-14  Myles C. Maxfield  <[email protected]>
+
+        CSSFontFaceSrcValue.cssText should be quoted consistently with other browsers
+        https://bugs.webkit.org/show_bug.cgi?id=230273
+        <rdar://problem/79644124>
+
+        Reviewed by Darin Adler.
+
+        * fast/css/font-face-src-parsing-expected.txt:
+
 2021-09-14  Ayumi Kojima  <[email protected]>
 
         Run tests in fast/forms/ios by default in EWS.

Modified: trunk/LayoutTests/fast/css/font-face-src-parsing-expected.txt (282414 => 282415)


--- trunk/LayoutTests/fast/css/font-face-src-parsing-expected.txt	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/LayoutTests/fast/css/font-face-src-parsing-expected.txt	2021-09-14 22:19:41 UTC (rev 282415)
@@ -2,18 +2,18 @@
 
 Valid rules form the stylesheet:
 
-@font-face { src: url(font.ttf); }
-@font-face { src: url(http://foo/bar/font.ttf); }
-@font-face { src: url(font.svg#id); }
-@font-face { src: url(font.ttf) format(truetype); }
-@font-face { src: url(font.woff) format(woff), local(font2); }
-@font-face { src: url(font2.ttf); }
-@font-face { src: url(font2.ttf) format(truetype); }
-@font-face { src: url(font3.otf) format(opentype), local(foo bar); }
-@font-face { src: local(foo); }
-@font-face { src: local(font), local(foo bar); }
-@font-face { src: local(foo); }
-@font-face { src: local(foo bar); }
+@font-face { src: url("font.ttf"); }
+@font-face { src: url("http://foo/bar/font.ttf"); }
+@font-face { src: url("font.svg#id"); }
+@font-face { src: url("font.ttf") format("truetype"); }
+@font-face { src: url("font.woff") format("woff"), local("font2"); }
+@font-face { src: url("font2.ttf"); }
+@font-face { src: url("font2.ttf") format("truetype"); }
+@font-face { src: url("font3.otf") format("opentype"), local("foo bar"); }
+@font-face { src: local("foo"); }
+@font-face { src: local("font"), local("foo bar"); }
+@font-face { src: local("foo"); }
+@font-face { src: local("foo bar"); }
 Expected result for valid rules:
 
 @font-face { src: url(font.ttf); }

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282414 => 282415)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-14 22:19:41 UTC (rev 282415)
@@ -1,3 +1,17 @@
+2021-09-14  Myles C. Maxfield  <[email protected]>
+
+        CSSFontFaceSrcValue.cssText should be quoted consistently with other browsers
+        https://bugs.webkit.org/show_bug.cgi?id=230273
+        <rdar://problem/79644124>
+
+        Reviewed by Darin Adler.
+
+        This is being upstreamed in https://github.com/web-platform-tests/wpt/pull/30784.
+
+        * web-platform-tests/css/css-fonts/font-family-src-quoted-expected.txt: Added.
+        * web-platform-tests/css/css-fonts/font-family-src-quoted.html: Added.
+        * web-platform-tests/css/cssom/cssom-fontfacerule-expected.txt:
+
 2021-09-14  Nikos Mouchtaris  <[email protected]>
 
         Add wpts for sin,cos,tan

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted-expected.txt (0 => 282415)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted-expected.txt	2021-09-14 22:19:41 UTC (rev 282415)
@@ -0,0 +1,3 @@
+
+PASS font-family-src-quoted
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted.html (0 => 282415)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted.html	2021-09-14 22:19:41 UTC (rev 282415)
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta charset=utf-8>
+<link rel="author" title="Myles C. Maxfield" href=""
+<link rel="help" href="" />
+<meta name="assert" content="Tests that local() and url() in serialization of @font-face blocks are quoted"/>
+<script type="text/_javascript_" src=""
+<script type="text/_javascript_" src=""
+<style id="style">
+/* 0 */
+@font-face {
+    font-family: "A";
+    src: local("B");
+}
+/* 1 */
+@font-face {
+    font-family: "C";
+    src: url("D") format("opentype");
+}
+/* 2 */
+@font-face {
+    font-family: "E";
+    src: url("F") format("opentype");
+}
+/* 3 */
+@font-face {
+    font-family: "G";
+    src: url("H") format("open\"type");
+}
+/* 4 */
+@font-face {
+    font-family: "I";
+    src: url("J") format("open\A type");
+}
+/* 5 */
+@font-face {
+    font-family: "K";
+    src: url("L") format("open\\type");
+}
+/* 6 */
+@font-face {
+    font-family: "M";
+    src: url("N\"O") format("opentype");
+}
+/* 7 */
+@font-face {
+    font-family: "P";
+    src: url("Q\A R") format("opentype");
+}
+/* 8 */
+@font-face {
+    font-family: "S";
+    src: url("T\\U") format("opentype");
+}
+/* 9 */
+@font-face {
+    font-family: "V";
+    src: local("W\"X");
+}
+/* 10 */
+@font-face {
+    font-family: "Y";
+    src: local("Z\A A");
+}
+/* 11 */
+@font-face {
+    font-family: "B";
+    src: local("C\\D");
+}
+</style>
+</head>
+<body>
+<script>
+test(function(t) {
+    let rules = document.getElementById("style").sheet.cssRules;
+    assert_not_equals(rules[0].cssText.indexOf('local("B")'), -1);
+    assert_not_equals(rules[1].cssText.indexOf('opentype'), -1);
+    assert_not_equals(rules[2].cssText.indexOf('F")'), -1);
+    assert_not_equals(rules[3].cssText.indexOf('format(\"open\\\"type\")'), -1);
+    assert_not_equals(rules[4].cssText.indexOf('format(\"open\\a type\")'), -1);
+    assert_not_equals(rules[5].cssText.indexOf('format(\"open\\\\type\")'), -1);
+    assert_not_equals(rules[9].cssText.indexOf('local(\"W\\\"X\")'), -1);
+    assert_not_equals(rules[10].cssText.indexOf('local(\"Z\\a A\")'), -1);
+    assert_not_equals(rules[11].cssText.indexOf('local(\"C\\\\D\")'), -1);
+});
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-fontfacerule-expected.txt (282414 => 282415)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-fontfacerule-expected.txt	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-fontfacerule-expected.txt	2021-09-14 22:19:41 UTC (rev 282415)
@@ -1,3 +1,3 @@
 
-FAIL CSSStyleDeclaration values are represented within CSSFontFaceRule assert_equals: expected "url(\"http://foo/bar/font.ttf\")" but got "url(http://foo/bar/font.ttf)"
+PASS CSSStyleDeclaration values are represented within CSSFontFaceRule
 

Modified: trunk/Source/WTF/ChangeLog (282414 => 282415)


--- trunk/Source/WTF/ChangeLog	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/Source/WTF/ChangeLog	2021-09-14 22:19:41 UTC (rev 282415)
@@ -1,3 +1,13 @@
+2021-09-14  Myles C. Maxfield  <[email protected]>
+
+        CSSFontFaceSrcValue.cssText should be quoted consistently with other browsers
+        https://bugs.webkit.org/show_bug.cgi?id=230273
+        <rdar://problem/79644124>
+
+        Reviewed by Darin Adler.
+
+        * wtf/unicode/CharacterNames.h:
+
 2021-09-14  Youenn Fablet  <[email protected]>
 
         Enable RTCRtpScriptTransform by default

Modified: trunk/Source/WTF/wtf/unicode/CharacterNames.h (282414 => 282415)


--- trunk/Source/WTF/wtf/unicode/CharacterNames.h	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/Source/WTF/wtf/unicode/CharacterNames.h	2021-09-14 22:19:41 UTC (rev 282415)
@@ -72,6 +72,7 @@
 constexpr UChar leftToRightIsolate = 0x2066;
 constexpr UChar leftToRightMark = 0x200E;
 constexpr UChar leftToRightOverride = 0x202D;
+constexpr UChar lowLine = 0x005F;
 constexpr UChar minusSign = 0x2212;
 constexpr UChar narrowNoBreakSpace = 0x202F;
 constexpr UChar narrowNonBreakingSpace = 0x202F;
@@ -84,6 +85,7 @@
 constexpr UChar popDirectionalIsolate = 0x2069;
 constexpr UChar quotationMark = 0x0022;
 constexpr UChar replacementCharacter = 0xFFFD;
+constexpr UChar reverseSolidus = 0x005C;
 constexpr UChar rightDoubleQuotationMark = 0x201D;
 constexpr UChar rightSingleQuotationMark = 0x2019;
 constexpr UChar rightToLeftEmbed = 0x202B;
@@ -149,6 +151,7 @@
 using WTF::Unicode::leftToRightIsolate;
 using WTF::Unicode::leftToRightMark;
 using WTF::Unicode::leftToRightOverride;
+using WTF::Unicode::lowLine;
 using WTF::Unicode::minusSign;
 using WTF::Unicode::narrowNoBreakSpace;
 using WTF::Unicode::narrowNonBreakingSpace;
@@ -158,7 +161,9 @@
 using WTF::Unicode::objectReplacementCharacter;
 using WTF::Unicode::popDirectionalFormatting;
 using WTF::Unicode::popDirectionalIsolate;
+using WTF::Unicode::quotationMark;
 using WTF::Unicode::replacementCharacter;
+using WTF::Unicode::reverseSolidus;
 using WTF::Unicode::rightDoubleQuotationMark;
 using WTF::Unicode::rightSingleQuotationMark;
 using WTF::Unicode::rightToLeftEmbed;

Modified: trunk/Source/WebCore/ChangeLog (282414 => 282415)


--- trunk/Source/WebCore/ChangeLog	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/Source/WebCore/ChangeLog	2021-09-14 22:19:41 UTC (rev 282415)
@@ -1,3 +1,23 @@
+2021-09-14  Myles C. Maxfield  <[email protected]>
+
+        CSSFontFaceSrcValue.cssText should be quoted consistently with other browsers
+        https://bugs.webkit.org/show_bug.cgi?id=230273
+        <rdar://problem/79644124>
+
+        Reviewed by Darin Adler.
+
+        In a src: line like "src: local(foobar)", Firefox and Chrome will both quote
+        "foobar" when reading out of the OM. Same thing with "src: url(foobar)".
+        We should match them.
+
+        Test: imported/w3c/web-platform-tests/css/css-fonts/font-family-src-quoted.html
+
+        * css/CSSFontFaceSrcValue.cpp:
+        (WebCore::CSSFontFaceSrcValue::customCSSText const):
+        * css/CSSMarkup.cpp:
+        (WebCore::serializeIdentifier):
+        (WebCore::serializeString):
+
 2021-09-14  Youenn Fablet  <[email protected]>
 
         Enable RTCRtpScriptTransform by default

Modified: trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp (282414 => 282415)


--- trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp	2021-09-14 22:19:41 UTC (rev 282415)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "CSSFontFaceSrcValue.h"
+#include "CSSMarkup.h"
 #include "CachedFont.h"
 #include "CachedFontLoadRequest.h"
 #include "CachedResourceLoader.h"
@@ -65,10 +66,11 @@
 
 String CSSFontFaceSrcValue::customCSSText() const
 {
+    // FIXME: URLs should not be absolutized, but instead should be serialized exactly as they were specified.
     const char* prefix = isLocal() ? "local(" : "url(";
     if (m_format.isEmpty())
-        return makeString(prefix, m_resource, ')');
-    return makeString(prefix, m_resource, ')', " format(", m_format, ')');
+        return makeString(prefix, serializeString(m_resource), ")");
+    return makeString(prefix, serializeString(m_resource), ")", " format(", serializeString(m_format), ")");
 }
 
 bool CSSFontFaceSrcValue::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const

Modified: trunk/Source/WebCore/css/CSSMarkup.cpp (282414 => 282415)


--- trunk/Source/WebCore/css/CSSMarkup.cpp	2021-09-14 22:11:30 UTC (rev 282414)
+++ trunk/Source/WebCore/css/CSSMarkup.cpp	2021-09-14 22:19:41 UTC (rev 282415)
@@ -98,11 +98,11 @@
 
         if (!c)
             appendTo.append(replacementCharacter);
-        else if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
+        else if (c <= 0x1f || c == deleteCharacter || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
             serializeCharacterAsCodePoint(c, appendTo);
-        else if (c == 0x2d && isFirst && index == identifier.length())
+        else if (c == hyphenMinus && isFirst && index == identifier.length())
             serializeCharacter(c, appendTo);
-        else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
+        else if (0x80 <= c || c == hyphenMinus || c == lowLine || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
             appendTo.appendCharacter(c);
         else
             serializeCharacter(c, appendTo);
@@ -110,7 +110,7 @@
         if (isFirst) {
             isFirst = false;
             isSecond = true;
-            isFirstCharHyphen = (c == 0x2d);
+            isFirstCharHyphen = (c == hyphenMinus);
         } else if (isSecond)
             isSecond = false;
     }
@@ -125,9 +125,9 @@
         UChar32 c = string.characterStartingAt(index);
         index += U16_LENGTH(c);
 
-        if (c <= 0x1f || c == 0x7f)
+        if (c <= 0x1f || c == deleteCharacter)
             serializeCharacterAsCodePoint(c, appendTo);
-        else if (c == 0x22 || c == 0x5c)
+        else if (c == quotationMark || c == reverseSolidus)
             serializeCharacter(c, appendTo);
         else
             appendTo.appendCharacter(c);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to