string-util: introduce STRING_FILENAME_PART flag for string_is_safe()
Whenever we are validating a string that shall appear in a filename eventually we want to use filename_part_is_valid() rather than file filename_is_valid(). Let's add explicit support for that to string_is_safe(), since it's actually a really common case.
This commit is contained in:
@@ -1139,6 +1139,9 @@ bool string_is_safe(const char *p, StringSafeFlags flags) {
|
||||
if (FLAGS_SET(flags, STRING_FILENAME) && !filename_is_valid(p))
|
||||
return false;
|
||||
|
||||
if (FLAGS_SET(flags, STRING_FILENAME_PART) && !filename_part_is_valid(p))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,8 @@ typedef enum StringSafeFlags {
|
||||
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, …) */
|
||||
STRING_FILENAME_PART = 1 << 7, /* Verify the string is valid as part of a regular filename */
|
||||
STRING_DISALLOW_WHITESPACE = 1 << 8, /* Refuse whitespace (space, tab, newline, …) */
|
||||
} StringSafeFlags;
|
||||
|
||||
bool string_is_safe(const char *p, StringSafeFlags flags) _pure_;
|
||||
|
||||
Reference in New Issue
Block a user