fix: look up unquoted font-family names containing spaces - #494
Conversation
convertFontFamily split the font-family attribute with split_attr_list, which replaces commas with spaces before shlex.split. An unquoted family name such as "Cascadia Code" was therefore split into "Cascadia" and "Code" and never matched a font registered under its full name, so the default font was used instead. Font-family splitting now uses a dedicated split_font_family_list that separates only on commas, yielding the full name first and the individual words afterwards so the previous lookup behaviour still works as a fallback. Closes deeplook#374
|
Thanks—this fixes the intended case: unquoted multi-word families such as One blocking edge case: font-family: "Foo, Bar", Arialcauses This can abort SVG conversion for a valid Could we split on commas only when outside quoted strings (respecting escapes), and add a regression test for |
A comma inside a quoted CSS family name (e.g. "Foo, Bar", Arial) was treated as a family separator, handing shlex.split() unmatched quote fragments and raising ValueError: No closing quotation, which could abort conversion of a valid font-family value.
|
Good catch, thanks. Fixed in 1686c3f: Added |
for more information, see https://pre-commit.ci
|
I'd be happy to include this in the next release which is just around the corner once this is cleaned-up. |
|
Happy to get it in. Current state on The other loose end I noticed was the assertion in If "cleaned-up" means something more specific, say the word and I will do it. The branch has four commits including a pre-commit.ci autofix, so I can squash to two (fix + test) if you would rather not carry that in history. |
|
Thanks! |
Closes #374
convertFontFamilysplit the font-family attribute withsplit_attr_list, which replaces commas with spaces beforeshlex.split, so an unquoted family name likeCascadia CodebecameCascadiaandCodeand never matched a font registered under its full name.Splitting now separates only on commas, yielding the full name first and the individual words afterwards so the previous lookup still works as a fallback. New test in
tests/test_fonts.pyfails without the change (Cascadiainstead ofCourier) and passes with it.