Bug 2067259 - When FamilyName is used for font names in src:local(), force its syntax to be Quoted. r=firefox-style-system-reviewers,emilio

Although the spec seems a little unclear on this IMO, it matches the behavior of both Chrome and Safari,
and is what css/css-fonts/font-family-src-quoted.html asserts:
https://github.com/web-platform-tests/wpt/blob/59ff8a4854a8d2d32ca0dc113760f2aaad70f4b5/css/css-fonts/font-family-src-quoted.html#L7

Differential Revision: https://phabricator.services.mozilla.com/D325335
This commit is contained in:
Jonathan Kew
2026-09-12 10:19:34 +00:00
committed by jkew@mozilla.com
parent 035464ff93
commit b0b4f61f55
2 changed files with 25 additions and 3 deletions
+6 -3
View File
@@ -11,6 +11,7 @@ use crate::error_reporting::ContextualParseError;
use crate::parser::{Parse, ParserContext};
use crate::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use crate::values::computed::FontWeight;
use crate::values::computed::font::FontFamilyNameSyntax;
use crate::values::generics::font::FontStyle as GenericFontStyle;
use crate::values::specified::{Angle, url::SpecifiedUrl};
use cssparser::{Parser, RuleBodyParser, SourceLocation};
@@ -501,9 +502,11 @@ impl Parse for Source {
.try_parse(|input| input.expect_function_matching("local"))
.is_ok()
{
return input
.parse_nested_block(|input| FamilyName::parse(context, input))
.map(Source::Local);
let mut family_name =
input.parse_nested_block(|input| FamilyName::parse(context, input))?;
// Force src:local() names to always serialize as quoted strings.
family_name.syntax = FontFamilyNameSyntax::Quoted;
return Ok(Source::Local(family_name));
}
let url = SpecifiedUrl::parse(context, input)?;
@@ -53,6 +53,21 @@
font-family: "B";
src: local("C\\D");
}
/* 9 */
@font-face {
font-family: "I";
src: local(ident);
}
/* 10 */
@font-face {
font-family: "J";
src: local(two idents);
}
/* 11 */
@font-face {
font-family: "K";
src: url(/path/to/font.ttf);
}
</style>
</head>
<body>
@@ -68,6 +83,10 @@ test(function(t) {
assert_not_equals(rules[6].cssText.indexOf('local(\"W\\\"X\")'), -1);
assert_not_equals(rules[7].cssText.indexOf('local(\"Z\\a A\")'), -1);
assert_not_equals(rules[8].cssText.indexOf('local(\"C\\\\D\")'), -1);
// serialization is quoted even if source was unquoted:
assert_not_equals(rules[9].cssText.indexOf('local(\"ident\")'), -1);
assert_not_equals(rules[10].cssText.indexOf('local(\"two idents\")'), -1);
assert_not_equals(rules[11].cssText.indexOf('url(\"/path/to/font.ttf\")'), -1);
});
</script>
</body>