Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS @font-face src string allows invalid items #18454

Merged
merged 2 commits into from Dec 20, 2022

Conversation

hamishwillee
Copy link
Collaborator

@hamishwillee hamishwillee commented Dec 20, 2022

The CSS @font-face at rule takes as a src a comma separate list of possible font descriptors. As per the spec here the parser is supposed to treat each item in the src separately, adding those that are valid and dropping those that are invalid or not supported. However a number of browser will drop the whole src string if any item is not understood.

  • Firefox starts handling items properly from FF109.
  • Chrome "somewhat" handles this properly in FF108. Specifically, even though they do not support tech() they will drop an item that uses tech() and not the whole string. However if you use another value like fred() they will drop the whole line. In other words, not a future proof implementation as new values are added, but works for the currently supported set.
  • Safari doesn't want to display its developer tools for me, so I don't know - have put as false.

My test code is to run this in a console:

s = document.createElement("style");
document.body.appendChild(s);
s.textContent = "@font-face { font-family: x; src: url('x.woff2') format('woff2'),url('y.otf') format(opentype) fred(incremental); }";
let thingy = document.styleSheets[document.styleSheets.length-1].cssRules[0].cssText
thingy;

If the src is present in "thingy" then the string is parsed properly. This fails for chrome, but if you change fred to tech above you can see it works for that single (most important) case.

This comes out of discussion in w3c/csswg-drafts#7753 (comment)

FYI @queengooborg

@github-actions github-actions bot added the data:css 🎨 Compat data for CSS features. https://developer.mozilla.org/docs/Web/CSS label Dec 20, 2022
@queengooborg queengooborg merged commit 5e08afa into mdn:main Dec 20, 2022
@hamishwillee hamishwillee deleted the fontface_src_item branch December 20, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:css 🎨 Compat data for CSS features. https://developer.mozilla.org/docs/Web/CSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants