From 817adbf22592955244aecad435ce0555707dba1a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 6 May 2025 19:27:45 -0400 Subject: Error checking for path components --- src/stdlib/paths.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/stdlib/paths.c') diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 04c6f7ee..86095f76 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -63,6 +63,9 @@ public Path_t Path$from_str(const char *str) else if (streq(str, "~")) return HOME_PATH; else if (streq(str, ".")) return CURDIR_PATH; + if (strchr(str, ';') != NULL) + fail("Path has illegal character (semicolon): ", str); + Path_t result = {.components={}}; if (str[0] == '/') { result.type.$tag = PATH_ABSOLUTE; @@ -608,6 +611,8 @@ public Text_t Path$extension(Path_t path, bool full) public Path_t Path$with_component(Path_t path, Text_t component) { + if (Text$has(component, Text("/")) || Text$has(component, Text(";"))) + fail("Path component has invalid characters: ", component); Path_t result = { .type.$tag=path.type.$tag, .components=path.components, @@ -623,6 +628,9 @@ public Path_t Path$with_extension(Path_t path, Text_t extension, bool replace) if (path.components.length == 0) fail("A path with no components can't have an extension!"); + if (Text$has(extension, Text("/")) || Text$has(extension, Text(";"))) + fail("Path extension has invalid characters: ", extension); + Path_t result = { .type.$tag=path.type.$tag, .components=path.components, -- cgit v1.2.3