style: Make font-family serialization algorithm a bit more conservative.

So as to avoid serializing as identifiers font-families with spaces as part of
the identifier. This avoids serializing confusing escaped sequences if the
beginning of the stuff after the space happens to not be a valid ident start.

This is an slightly more restrictive version of the existing logic, which
happens to also match other browsers in my testing.

Differential Revision: https://phabricator.services.mozilla.com/D62376
This commit is contained in:
Emilio Cobos Álvarez 2020-02-12 11:32:47 +00:00
parent ef2d934dac
commit 5cedc45858

View file

@ -352,19 +352,22 @@ impl SingleFontFamily {
};
let mut value = first_ident.as_ref().to_owned();
let mut serialize_quoted = value.contains(' ');
// These keywords are not allowed by themselves.
// The only way this value can be valid with with another keyword.
if reserved {
let ident = input.expect_ident()?;
serialize_quoted = serialize_quoted || ident.contains(' ');
value.push(' ');
value.push_str(&ident);
}
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
serialize_quoted = serialize_quoted || ident.contains(' ');
value.push(' ');
value.push_str(&ident);
}
let syntax = if value.starts_with(' ') || value.ends_with(' ') || value.contains(" ") {
let syntax = if serialize_quoted {
// For font family names which contains special white spaces, e.g.
// `font-family: \ a\ \ b\ \ c\ ;`, it is tricky to serialize them
// as identifiers correctly. Just mark them quoted so we don't need