Skip to content

fix: look up unquoted font-family names containing spaces - #494

Merged
deeplook merged 5 commits into
deeplook:mainfrom
Sanjays2402:fix/font-family-unquoted-space
Jul 31, 2026
Merged

fix: look up unquoted font-family names containing spaces#494
deeplook merged 5 commits into
deeplook:mainfrom
Sanjays2402:fix/font-family-unquoted-space

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #374

convertFontFamily split the font-family attribute with split_attr_list, which replaces commas with spaces before shlex.split, so an unquoted family name like Cascadia Code became Cascadia and Code and 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.py fails without the change (Cascadia instead of Courier) and passes with it.

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
@deeplook

Copy link
Copy Markdown
Owner

Thanks—this fixes the intended case: unquoted multi-word families such as font-family: Cascadia Code are now looked up as the complete name before falling back to individual words. The focused font tests pass.

One blocking edge case: split_font_family_list() uses attr.split(","), which splits commas inside quoted CSS family names. For example:

font-family: "Foo, Bar", Arial

causes shlex.split() to receive unmatched quote fragments and raises:

ValueError: No closing quotation

This can abort SVG conversion for a valid font-family value.

Could we split on commas only when outside quoted strings (respecting escapes), and add a regression test for "Foo, Bar", Arial?

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.
@Sanjays2402

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. Fixed in 1686c3f: split_font_family_list() now walks the string and only breaks on commas that are outside a quoted section, tracking the active quote char and honouring backslash escapes, so "Foo, Bar", Arial yields ["Foo, Bar", "Arial"] instead of feeding shlex unbalanced fragments.

Added test_font_family_quoted_name_containing_comma in tests/test_fonts.py covering your exact value with both double and single quotes, plus a convertFontFamily() assertion so the valid value resolves rather than aborting. I checked it is not vacuous: with the split reverted to attr.split(",") the test fails with ValueError: No closing quotation, and passes with the fix. Full tests/test_fonts.py is green (40 passed, 2 skipped).

@deeplook

Copy link
Copy Markdown
Owner

I'd be happy to include this in the next release which is just around the corner once this is cleaned-up.

@Sanjays2402

Copy link
Copy Markdown
Contributor Author

Happy to get it in. Current state on 7cfb105: all checks green, and I have just added the missing CHANGELOG entry under Unreleased/Fixed covering both halves (multi-word unquoted name lookup for #374, and commas inside a quoted name no longer feeding shlex an unbalanced quote).

The other loose end I noticed was the assertion in test_font_family_quoted_name_containing_comma: it originally pinned the resolved fallback name, which is environment-dependent and went red on the Ubuntu jobs, so dfacd2c reduced it to asserting a name comes back at all. The exact-list assertions on split_font_family_list() still cover the actual parsing.

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.

@deeplook
deeplook merged commit dcc2fe5 into deeplook:main Jul 31, 2026
16 checks passed
@deeplook

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when svg file contains references to font with space in its name

2 participants