string-util: add STRING_DISALLOW_WHITESPACE for string_is_safe
Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1129,6 +1129,9 @@ bool string_is_safe(const char *p, StringSafeFlags flags) {
|
||||
if (!FLAGS_SET(flags, STRING_ALLOW_GLOBS) && strchr(GLOB_CHARS, *t))
|
||||
return false;
|
||||
|
||||
if (FLAGS_SET(flags, STRING_DISALLOW_WHITESPACE) && strchr(WHITESPACE, *t))
|
||||
return false;
|
||||
|
||||
if (FLAGS_SET(flags, STRING_ASCII) && (uint8_t) *t >= 0x80)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -222,13 +222,14 @@ static inline int strdup_to(char **ret, const char *src) {
|
||||
}
|
||||
|
||||
typedef enum StringSafeFlags {
|
||||
STRING_ASCII = 1 << 0, /* Verify string is 7-Bit ASCII (rather than just UTF-8) */
|
||||
STRING_ALLOW_EMPTY = 1 << 1, /* Allow empty strings */
|
||||
STRING_ALLOW_NEWLINES = 1 << 2, /* Allow newlines (\n) */
|
||||
STRING_ALLOW_BACKSLASHES = 1 << 3, /* Allow backslashes (\) */
|
||||
STRING_ALLOW_QUOTES = 1 << 4, /* Allow quotes (" or ') */
|
||||
STRING_ALLOW_GLOBS = 1 << 5, /* Allow globs (?, * or [) */
|
||||
STRING_FILENAME = 1 << 6, /* Verify the string is valid as regular filename */
|
||||
STRING_ASCII = 1 << 0, /* Verify string is 7-Bit ASCII (rather than just UTF-8) */
|
||||
STRING_ALLOW_EMPTY = 1 << 1, /* Allow empty strings */
|
||||
STRING_ALLOW_NEWLINES = 1 << 2, /* Allow newlines (\n) */
|
||||
STRING_ALLOW_BACKSLASHES = 1 << 3, /* Allow backslashes (\) */
|
||||
STRING_ALLOW_QUOTES = 1 << 4, /* Allow quotes (" or ') */
|
||||
STRING_ALLOW_GLOBS = 1 << 5, /* Allow globs (?, * or [) */
|
||||
STRING_FILENAME = 1 << 6, /* Verify the string is valid as regular filename */
|
||||
STRING_DISALLOW_WHITESPACE = 1 << 7, /* Refuse whitespace (space, tab, newline, …) */
|
||||
} StringSafeFlags;
|
||||
|
||||
bool string_is_safe(const char *p, StringSafeFlags flags) _pure_;
|
||||
|
||||
Reference in New Issue
Block a user