diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-05-06 19:27:45 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-05-06 19:27:45 -0400 |
| commit | 817adbf22592955244aecad435ce0555707dba1a (patch) | |
| tree | 5bde62f686921d348b74e78903f1b8ed6bf746d1 /src/stdlib/paths.c | |
| parent | ce098c6401335b14ed9f92ee795d5ba6afb45d2e (diff) | |
Error checking for path components
Diffstat (limited to 'src/stdlib/paths.c')
| -rw-r--r-- | src/stdlib/paths.c | 8 |
1 files changed, 8 insertions, 0 deletions
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, |
