From bc89c94c76ce5b50f7b1508dd8d4be4bd37a50f5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 22 Feb 2026 09:41:09 -0500 Subject: Fixes for Path.with_extension() --- src/stdlib/paths.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/stdlib/paths.c') diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index e50f0420..9e4face7 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -755,14 +755,15 @@ OptionalPath_t Path$with_extension(Path_t path, Text_t extension, bool replace) if (!path || path[0] == '\0') return NULL; static char buf[PATH_MAX]; + const char *ext = Text$as_c_string(extension); if (replace) { char *base = (char *)base_name_start(path); char *dot = strchrnul(base, '.'); - if (extension.length > 0) - snprintf(buf, sizeof(buf), "%.*s.%s", (int)(dot - path), path, Text$as_c_string(extension)); - else snprintf(buf, sizeof(buf), "%.*s", (int)(dot - path), path); + if (ext[0] == '.' || ext[0] == '\0') snprintf(buf, sizeof(buf), "%.*s%s", (int)(dot - path), path, ext); + else snprintf(buf, sizeof(buf), "%.*s.%s", (int)(dot - path), path, ext); } else { - snprintf(buf, sizeof(buf), "%s.%s", path, Text$as_c_string(extension)); + if (ext[0] == '.' || ext[0] == '\0') snprintf(buf, sizeof(buf), "%s%s", path, ext); + else snprintf(buf, sizeof(buf), "%s.%s", path, ext); } return path_from_buf(buf); } -- cgit v1.2.3