Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-06-18 13:32:12 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-06-18 13:32:12 +0300
commit324e10e76af43788c282e5a08eb18fde48bb488b (patch)
treeb2c3ad71aefba138cd8030c0b066dab4a747207c /source/blender/blenlib
parent5e47f365e1e743ca1cc86e9f1dad936d5ce7e93a (diff)
parent579631819f0136ab0fbb0f6c7c21265b468940dc (diff)
Merge branch 'master' into blender2.8
Conflicts: source/blender/makesrna/intern/rna_space.c
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_path_util.h1
-rw-r--r--source/blender/blenlib/intern/path_util.c31
2 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index ebdf116ba7a..b4329bf81ac 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -75,6 +75,7 @@ bool BLI_path_extension_check(const char *str, const char *ext) ATTR_NONNULL() A
bool BLI_path_extension_check_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
bool BLI_path_extension_check_array(const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL();
bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
bool BLI_ensure_filename(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index cff11ec0361..6272f2109d2 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1438,6 +1438,37 @@ bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch)
return false;
}
+/**
+ * Does basic validation of the given glob string, to prevent common issues from string truncation.
+ *
+ * For now, only forbids last group to be a wildcard-only one, if there are more than one group
+ * (i.e. things like "*.txt;*.cpp;*" are changed to "*.txt;*.cpp;")
+ *
+ * \returns true if it had to modify given \a ext_fnmatch pattern.
+ */
+bool BLI_path_extension_glob_validate(char *ext_fnmatch)
+{
+ bool only_wildcards = false;
+
+ for (size_t i = strlen(ext_fnmatch); i-- > 0; ) {
+ if (ext_fnmatch[i] == ';') {
+ /* Group separator, we truncate here if we only had wildcards so far. Otherwise, all is sound and fine. */
+ if (only_wildcards) {
+ ext_fnmatch[i] = '\0';
+ return true;
+ }
+ return false;
+ }
+ if (!ELEM(ext_fnmatch[i], '?', '*')) {
+ /* Non-wildcard char, we can break here and consider the pattern valid. */
+ return false;
+ }
+ /* So far, only wildcards in last group of the pattern... */
+ only_wildcards = true;
+ }
+ /* Only one group in the pattern, so even if its only made of wildcard(s), it is assumed vaid. */
+ return false;
+}
/**
* Removes any existing extension on the end of \a path and appends \a ext.