From 5cedc45858786c90e38507b1459073b5d92b6c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 12 Feb 2020 11:32:47 +0000 Subject: [PATCH] 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 --- components/style/values/computed/font.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 642dbc37eeb..6d17f9fa699 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -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