8000 font-face src list fails early if component fails · WebKit/WebKit@6782d34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6782d34

Browse files
committed
font-face src list fails early if component fails
https://bugs.webkit.org/show_bug.cgi?id=250332 rdar://104039050 Reviewed by Tim Nguyen. If one component of the list fails we should not immediately fail the parsing of font src, since one valid component will validate the descriptor. Therefore, we should just fail the src descriptor parsing if all components have failed. "A component with a parse error does not invalidate the entire descriptor if there's some other valid component present." Reference: https://github.com/web-platform-tests/wpt/blob/e9470cde64/css/css-fonts/parsing/font-face-src-list.html * LayoutTests/fast/css/font-face-src-parsing-expected.txt: * LayoutTests/fast/css/font-face-src-parsing.html: * LayoutTests/fast/css/font-face-unquoted-local-expected.html: Removed. * LayoutTests/fast/css/font-face-unquoted-local-expected.txt: Added. * LayoutTests/fast/css/font-face-unquoted-local.html: This test was making use of faulty behavior of src list failing early to build the test. * LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-list-expected.txt: * Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp: (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrc): Canonical link: https://commits.webkit.org/258749@main
1 parent 639329c commit 6782d34

File tree

8 files changed

+46
-68
lines changed

8 files changed

+46
-68
lines changed

LayoutTests/fast/css/font-face-src-parsing-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Valid rules from the stylesheet:
1414
@font-face { src: local("font"), local("foo bar"); }
1515
@font-face { src: local("foo"); }
1616
@font-face { src: local("foo bar"); }
17+
@font-face { src: url("font.ttf"); }
18+
@font-face { src: url("font.ttf"), local("font2"); }
19+
@font-face { src: local("font"); }
1720
Invalid rules from the stylesheet:
1821

1922
@font-face { }
2023
@font-face { }
2124
@font-face { }
2225
@font-face { }
2326
@font-face { }
24-
@font-face { }
25-
@font-face { }
26-
@font-face { }
2727

LayoutTests/fast/css/font-face-src-parsing.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@
3636
@font-face {
3737
src: local("foo bar");
3838
}
39-
</style>
40-
41-
<!-- Invalid src descriptor rules. -->
42-
<style>
43-
@font-face {
44-
src: url(font.ttf invalid);
45-
}
4639
@font-face {
4740
src: url(font.ttf),;
4841
}
@@ -52,6 +45,13 @@
5245
@font-face {
5346
src: ,local(font);
5447
}
48+
</style>
49+
50+
<!-- Invalid src descriptor rules. -->
51+
<style>
52+
@font-face {
53+
src: url(font.ttf invalid);
54+
}
5555
@font-face {
5656
src: url(font.ttf), invalid();
5757
}

LayoutTests/fast/css/font-face-unquoted-local-expected.html

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
PASS Check that src: local(unquoted name); is valid
3+
PASS Check that src: local(invalid '' name); is invalid
4+
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
<style>
2-
@font-face {
3-
font-family: ahem;
4-
src: local(unquoted name), url(../../resources/Ahem.ttf);
5-
}
6-
@font-face {
7-
font-family: invalid;
8-
src: local(invalid '' name), url(../../resources/Ahem.ttf);
9-
}
1+
<!DOCTYPE html>
2+
<script src="../../resources/testharness.js"></script>
3+
<script src="../../resources/testharnessreport.js"></script>
4+
<style id="testStyle">
105
</style>
11-
<p>This test ensures that unquoted font names are allowed in local().</p>
12-
13-
<p>The text below should be a series of black boxes.</p>
14-
<p style="font-family: ahem;">FAIL</p>
15-
16-
<p>The text below should not be a series of black boxes.</p>
17-
<p style="font-family: invalid;">SUCCESS</p>
18-
196
<script>
20-
if (window.testRunner) {
21-
testRunner.waitUntilDone();
22-
document.documentElement.offsetTop;
23-
setTimeout(function() { testRunner.notifyDone(); }, 200);
24-
}
7+
const sheet = testStyle.sheet;
8+
tests = [
9+
{ src: "local(unquoted name);", valid: true},
10+
{ src: "local(invalid '' name);", valid: false}
11+
];
12+
13+
for (let t of tests) {
14+
test(() => {
15+
assert_equals(sheet.cssRules.length, 0, "testSheet should initially be empty");
16+
sheet.insertRule("@font-face { src: " + t.src + "}");
17+
assert_equals(sheet.cssRules[0].style.getPropertyValue("src") != "", t.valid);
18+
sheet.deleteRule(0);
19+
}, "Check that src: " + t.src + " is " + (t.valid ? "valid" : "invalid"));
20+
}
2521
</script>

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ PASS Check that src: url("foo.ttf") format("embedded-opentype"), url("bar.html")
2626
PASS Check that src: url("foo.ttf") format(embedded-opentype), url("bar.html") is valid
2727
PASS Check that src: url("foo.ttf") format("svg"), url("bar.html") is valid
2828
PASS Check that src: url("foo.ttf") format(svg), url("bar.html") is valid
29-
FAIL Check that src: url("foo.ttf") format(xyzz 200px), url("bar.html") is valid assert_equals: expected true but got false
30-
FAIL Check that src: url("foo.ttf") format(xyzz), url("bar.html") is valid assert_equals: expected true but got false
29+
PASS Check that src: url("foo.ttf") format(xyzz 200px), url("bar.html") is valid
30+
PASS Check that src: url("foo.ttf") format(xyzz), url("bar.html") is valid
3131
FAIL Check that src: url("foo.ttf") dummy(xyzzy), url("bar.html") is valid assert_equals: expected true but got false
32-
FAIL Check that src: url("foo.ttf") format(), url("bar.html") is valid assert_equals: expected true but got false
33-
FAIL Check that src: url("foo.ttf") format(none), url("bar.html") is valid assert_equals: expected true but got false
32+
PASS Check that src: url("foo.ttf") format(), url("bar.html") is valid
33+
PASS Check that src: url("foo.ttf") format(none), url("bar.html") is valid
3434

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-list-expected.txt
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
FAIL Check that src: local(inherit), url(foo.ttf) is valid assert_equals: expected true but got false
3-
FAIL Check that src: local("myfont"), local(unset) is valid assert_equals: expected true but got false
4-
FAIL Check that src: local(), url(foo.ttf) is valid assert_equals: expected true but got false
5-
FAIL Check that src: local(12px monospace), url(foo.ttf) is valid assert_equals: expected true but got false
2+
PASS Check that src: local(inherit), url(foo.ttf) is valid
3+
PASS Check that src: local("myfont"), local(unset) is valid
4+
PASS Check that src: local(), url(foo.ttf) is valid
5+
PASS Check that src: local(12px monospace), url(foo.ttf) is valid
66
FAIL Check that src: local("myfont") format(opentype), url(foo.ttf) is valid assert_equals: expected true but got false
77
FAIL Check that src: url(not a valid url/bar.ttf), url(foo.ttf) is valid assert_equals: expected true but got false
8-
FAIL Check that src: url(foo.ttf) format(bad), url(foo.ttf) is valid assert_equals: expected true but got false
8+
PASS Check that src: url(foo.ttf) format(bad), url(foo.ttf) is valid
99
FAIL Check that src: url(foo.ttf) tech(unknown), url(foo.ttf) is valid assert_equals: expected true but got false
10-
FAIL Check that src: url(foo.ttf), url(something.ttf) format(broken) is valid assert_equals: expected true but got false
11-
FAIL Check that src: /* an empty component */, url(foo.ttf) is valid assert_equals: expected true but got false
10+
PASS Check that src: url(foo.ttf), url(something.ttf) format(broken) is valid
11+
PASS Check that src: /* an empty component */, url(foo.ttf) is valid
1212
FAIL Check that src: local(""), url(foo.ttf), unparseable-garbage, local("another font name") is valid assert_equals: expected true but got false
1313
PASS Check that src: local(), local(initial) is invalid
1414
PASS Check that src: local("textfont") format(opentype), local("emoji") tech(color-COLRv0) is invalid

Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,10 @@ RefPtr<CSSValueList> consumeFontFaceSrc(CSSParserTokenRange& range, const CSSPar
256256
parsedValue = consumeFontFaceSrcLocal(range);
257257
else
258258
parsedValue = consumeFontFaceSrcURI(range, context);
259-
if (!parsedValue)
260-
return nullptr;
261-
values->append(parsedValue.releaseNonNull());
259+
if (parsedValue)
260+
values->append(parsedValue.releaseNonNull());
262261
} while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
263-
return values;
262+
return values->size() ? values : nullptr;
264263
}
265264

266265
#if ENABLE(VARIATION_FONTS)

0 commit comments

Comments
 (0)
0