if (n <= 0 || n >= 256)
return false;
+ /* Don't allow "-" and "." as first or last char. (This is load-bearing, we want that "+"/"-" can be
+ * used as prefix for adding/removing tags from the list). */
+ if (strchr("-.", s[0]) ||
+ strchr("-.", s[n-1]))
+ return false;
+
return in_charset(s, ALPHANUMERICAL "-.");
}
assert_se(!machine_tag_is_valid("fööbar")); /* non-ASCII */
assert_se(!machine_tag_is_valid("foo/bar"));
assert_se(!machine_tag_is_valid("foo_bar"));
+ assert_se(!machine_tag_is_valid("-foo"));
+ assert_se(!machine_tag_is_valid("foo-"));
+ assert_se(!machine_tag_is_valid(".foo"));
+ assert_se(!machine_tag_is_valid("foo."));
/* Length boundary: 255 characters is fine, 256 is too long */
_cleanup_free_ char *max = strrep("a", 255), *over = strrep("a", 256);