Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion shared/font-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ export function mapWordFamilyFallback(wordFamily) {
*/
export function toCssFontFamily(fontName, options = {}) {
if (!fontName || typeof fontName !== 'string') return fontName;
const trimmed = fontName.trim();
let trimmed = fontName.trim();
// replace semicolon font fallback separators
if (trimmed.includes(';')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once semicolons become commas, the comma check on line 202 returns early -- no sans-serif fallback gets added.

works today because the import path already adds one, but if this function gets called with raw "Liberation Sans;Arial" it'll be missing a generic fallback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also.. needs tests for semicolon inputs -- the early return on line 202 skipping fallbacks is easy to miss without one. toCssFontFamily("Liberation Sans;Arial") and toCssFontFamily("Foo;Bar", { wordFamily: 'swiss' }) would cover it.

trimmed = trimmed
.split(';')
.map((part) => part.trim())
Comment on lines +195 to +198

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not split semicolons inside quoted font names

The new semicolon normalization splits on every ; without considering quotes, so a literal family like "Foo;Bar" is rewritten to "Foo, Bar" before the early comma return. That changes the actual font identifier and causes incorrect font matching for any document that uses quoted font names containing semicolons, which this function previously preserved.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattConnHarbour check and add a response if applicable/or not

.filter(Boolean)
.join(', ');
}
if (!trimmed || trimmed.includes(',')) return trimmed;

const { fallback, wordFamily } = options;
Expand Down
Loading