aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stdlib/paths.c8
-rw-r--r--src/stdlib/text.c2
-rw-r--r--src/stdlib/text.h2
3 files changed, 10 insertions, 2 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,
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 8607e165..cc8a4daf 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -1092,7 +1092,7 @@ public Text_t Text$replace(Text_t text, Text_t target, Text_t replacement)
return result;
}
-public bool Text$has(Text_t text, Text_t target)
+public PUREFUNC bool Text$has(Text_t text, Text_t target)
{
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), target_state = NEW_TEXT_ITER_STATE(target);
for (int64_t i = 0; i < text.length; i++) {
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index ffdebf68..47ede6f1 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -54,7 +54,7 @@ Text_t Text$without_prefix(Text_t text, Text_t prefix);
Text_t Text$without_suffix(Text_t text, Text_t suffix);
Text_t Text$replace(Text_t text, Text_t target, Text_t replacement);
Text_t Text$translate(Text_t text, Table_t translations);
-bool Text$has(Text_t text, Text_t target);
+PUREFUNC bool Text$has(Text_t text, Text_t target);
List_t Text$split(Text_t text, Text_t delimiter);
List_t Text$split_any(Text_t text, Text_t delimiters);
Closure_t Text$by_split(Text_t text, Text_t delimiter);