From 22ea71117c75602e7bb4046c2e67d1be8a775af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 24 Jun 2026 10:26:54 +0200 Subject: [PATCH] config: font_parse(): handle font family names with \-:, These characters have special meaning, and when they appear in the font *family name*, they need to be escaped in the font pattern. Before this patch, even if the user did escape them properly, _we_ un-escaped them in FcNameUnparse(), causing the wrong font to be loaded later. --- config.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 481d4c4f..824a4ded 100644 --- a/config.c +++ b/config.c @@ -4123,7 +4123,25 @@ config_font_parse(const char *pattern, struct config_font *font) FcPatternRemove(pat, FC_SIZE, 0); FcPatternRemove(pat, FC_PIXEL_SIZE, 0); - char *stripped_pattern = (char *)FcNameUnparse(pat); + /* Only the family part, with '\', '-', ':' and ',' \-escaped */ + FcChar8 *escaped_family = FcPatternFormat( + pat, (const FcChar8 *)"%{+family{%{family|escape(\\\\-:,)}}}"); + + /* Everything but the family, size and pixelsize */ + FcChar8 *rest = FcPatternFormat( + pat, (const FcChar8 *)"%{-family,size,pixelsize{%{=unparse}}}"); + + char *stripped_pattern = NULL; + if (escaped_family == NULL || rest == NULL) { + free(escaped_family); + free(rest); + stripped_pattern = (char *)FcNameUnparse(pat); + } else { + stripped_pattern = xasprintf("%s%s", escaped_family, rest); + free(escaped_family); + free(rest); + } + FcPatternDestroy(pat); LOG_DBG("%s: pt-size=%.2f, px-size=%d", stripped_pattern, pt_size, px_size);