Title: [243637] trunk
Revision
243637
Author
[email protected]
Date
2019-03-28 19:26:47 -0700 (Thu, 28 Mar 2019)

Log Message

FontFace constructor throws an exception when there is a name which starts with a number
https://bugs.webkit.org/show_bug.cgi?id=196232
<rdar://problem/49293978>

Reviewed by Ryosuke Niwa.

Source/WebCore:

We were technically following the spec, but Chrome and Firefox are both consistent and it was making a website break.
This is just a short-term fix until the underlying https://bugs.webkit.org/show_bug.cgi?id=196381 is fixed.

Test: fast/text/font-face-family.html

* css/FontFace.cpp:
(WebCore::FontFace::setFamily):

LayoutTests:

* fast/text/font-face-family-expected.txt: Added.
* fast/text/font-face-family.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (243636 => 243637)


--- trunk/LayoutTests/ChangeLog	2019-03-29 02:19:37 UTC (rev 243636)
+++ trunk/LayoutTests/ChangeLog	2019-03-29 02:26:47 UTC (rev 243637)
@@ -1,3 +1,14 @@
+2019-03-28  Myles C. Maxfield  <[email protected]>
+
+        FontFace constructor throws an exception when there is a name which starts with a number
+        https://bugs.webkit.org/show_bug.cgi?id=196232
+        <rdar://problem/49293978>
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/text/font-face-family-expected.txt: Added.
+        * fast/text/font-face-family.html: Added.
+
 2019-03-28  Ryosuke Niwa  <[email protected]>
 
         getBoundingClientRect always returns empty rect on a collapsed range

Added: trunk/LayoutTests/fast/text/font-face-family-expected.txt (0 => 243637)


--- trunk/LayoutTests/fast/text/font-face-family-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-face-family-expected.txt	2019-03-29 02:26:47 UTC (rev 243637)
@@ -0,0 +1,12 @@
+PASS new FontFace('a', 'url(garbage.otf)') is non-null.
+PASS new FontFace('4a', 'url(garbage.otf)') is non-null.
+PASS new FontFace('4"a', 'url(garbage.otf)') is non-null.
+PASS new FontFace('4\'a', 'url(garbage.otf)') is non-null.
+PASS new FontFace('4\'a"b', 'url(garbage.otf)') is non-null.
+PASS (new FontFace('a b', 'url(garbage.otf)')).family is "a b"
+PASS (new FontFace('a b, c', 'url(garbage.otf)')).family is "a b, c"
+PASS (new FontFace('ab,c', 'url(garbage.otf)')).family is "ab,c"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/text/font-face-family.html (0 => 243637)


--- trunk/LayoutTests/fast/text/font-face-family.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-face-family.html	2019-03-29 02:26:47 UTC (rev 243637)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+shouldBeNonNull("new FontFace('a', 'url(garbage.otf)')");
+shouldBeNonNull("new FontFace('4a', 'url(garbage.otf)')");
+shouldBeNonNull("new FontFace('4\"a', 'url(garbage.otf)')");
+shouldBeNonNull("new FontFace('4\\'a', 'url(garbage.otf)')");
+shouldBeNonNull("new FontFace('4\\'a\"b', 'url(garbage.otf)')");
+shouldBeEqualToString("(new FontFace('a b', 'url(garbage.otf)')).family", "a b");
+shouldBeEqualToString("(new FontFace('a b, c', 'url(garbage.otf)')).family", "a b, c");
+shouldBeEqualToString("(new FontFace('ab,c', 'url(garbage.otf)')).family", "ab,c");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (243636 => 243637)


--- trunk/Source/WebCore/ChangeLog	2019-03-29 02:19:37 UTC (rev 243636)
+++ trunk/Source/WebCore/ChangeLog	2019-03-29 02:26:47 UTC (rev 243637)
@@ -1,3 +1,19 @@
+2019-03-28  Myles C. Maxfield  <[email protected]>
+
+        FontFace constructor throws an exception when there is a name which starts with a number
+        https://bugs.webkit.org/show_bug.cgi?id=196232
+        <rdar://problem/49293978>
+
+        Reviewed by Ryosuke Niwa.
+
+        We were technically following the spec, but Chrome and Firefox are both consistent and it was making a website break.
+        This is just a short-term fix until the underlying https://bugs.webkit.org/show_bug.cgi?id=196381 is fixed.
+
+        Test: fast/text/font-face-family.html
+
+        * css/FontFace.cpp:
+        (WebCore::FontFace::setFamily):
+
 2019-03-28  Justin Fan  <[email protected]>
 
         [Web GPU] Replace 'unsigned long' with 'unsigned' when implementing u32 variables

Modified: trunk/Source/WebCore/css/FontFace.cpp (243636 => 243637)


--- trunk/Source/WebCore/css/FontFace.cpp	2019-03-29 02:19:37 UTC (rev 243636)
+++ trunk/Source/WebCore/css/FontFace.cpp	2019-03-29 02:26:47 UTC (rev 243637)
@@ -153,9 +153,11 @@
     if (family.isEmpty())
         return Exception { SyntaxError };
 
-    bool success = false;
-    if (auto value = parseString(family, CSSPropertyFontFamily))
-        success = m_backing->setFamilies(*value);
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=196381 Don't use a list here.
+    // See consumeFontFamilyDescriptor() in CSSPropertyParser.cpp for why we're using it.
+    auto list = CSSValueList::createCommaSeparated();
+    list->append(CSSValuePool::singleton().createFontFamilyValue(family));
+    bool success = m_backing->setFamilies(list);
     if (!success)
         return Exception { SyntaxError };
     return { };
@@ -293,6 +295,21 @@
 String FontFace::family() const
 {
     m_backing->updateStyleIfNeeded();
+
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=196381 This is only here because CSSFontFace erroneously uses a list of values instead of a single value.
+    // See consumeFontFamilyDescriptor() in CSSPropertyParser.cpp.
+    if (m_backing->families()->length() == 1) {
+        if (m_backing->families()->item(0)) {
+            auto& item = *m_backing->families()->item(0);
+            if (item.isPrimitiveValue()) {
+                auto& primitiveValue = downcast<CSSPrimitiveValue>(item);
+                if (primitiveValue.isFontFamily()) {
+                    auto& fontFamily = primitiveValue.fontFamily();
+                    return fontFamily.familyName;
+                }
+            }
+        }
+    }
     return m_backing->families()->cssText();
 }
 

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (243636 => 243637)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2019-03-29 02:19:37 UTC (rev 243636)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2019-03-29 02:26:47 UTC (rev 243637)
@@ -1087,7 +1087,7 @@
 
 static RefPtr<CSSValueList> consumeFontFamilyDescriptor(CSSParserTokenRange& range)
 {
-    // FIXME-NEWPARSER: For compatibility with the old parser, we have to make
+    // FIXME-NEWPARSER: https://bugs.webkit.org/show_bug.cgi?id=196381 For compatibility with the old parser, we have to make
     // a list here, even though the list always contains only a single family name.
     // Once the old parser is gone, we can delete this function, make the caller
     // use consumeFamilyName instead, and then patch the @font-face code to
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to