diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-27 11:35:55 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-27 11:35:55 +0100 |
commit | 9d555f5c6853c0f97136532d1c71ee3a06fd82dc (patch) | |
tree | 52ad1d2d7a27db0f74d6879cbce3fb495dd21051 /core | |
parent | 8b662c763e27b8dbbda21bde0694151c718aa725 (diff) | |
parent | 39922d7167178bab9587aa00a7a108b93db6240e (diff) |
Merge pull request #62499 from fire/gltf-binary-img-compression
Handle gltf binary images
Diffstat (limited to 'core')
-rw-r--r-- | core/string/ustring.cpp | 20 | ||||
-rw-r--r-- | core/string/ustring.h | 1 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 9e468f7075..b34d9f3271 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4342,6 +4342,9 @@ bool String::is_valid_html_color() const { return Color::html_is_valid(*this); } +// Changes made to the set of invalid filename characters must also be reflected in the String documentation for is_valid_filename. +static const char *invalid_filename_characters = ": / \\ ? * \" | % < >"; + bool String::is_valid_filename() const { String stripped = strip_edges(); if (*this != stripped) { @@ -4352,7 +4355,22 @@ bool String::is_valid_filename() const { return false; } - return !(find(":") != -1 || find("/") != -1 || find("\\") != -1 || find("?") != -1 || find("*") != -1 || find("\"") != -1 || find("|") != -1 || find("%") != -1 || find("<") != -1 || find(">") != -1); + Vector<String> chars = String(invalid_filename_characters).split(" "); + for (const String &ch : chars) { + if (contains(ch)) { + return false; + } + } + return true; +} + +String String::validate_filename() const { + Vector<String> chars = String(invalid_filename_characters).split(" "); + String name = strip_edges(); + for (int i = 0; i < chars.size(); i++) { + name = name.replace(chars[i], "_"); + } + return name; } bool String::is_valid_ip_address() const { diff --git a/core/string/ustring.h b/core/string/ustring.h index 6338f1d3cd..1582504c57 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -433,6 +433,7 @@ public: static const String invalid_node_name_characters; String validate_node_name() const; String validate_identifier() const; + String validate_filename() const; bool is_valid_identifier() const; bool is_valid_int() const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 07e1442faf..3b2d29734d 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1695,6 +1695,7 @@ static void _register_variant_builtin_methods() { bind_string_method(json_escape, sarray(), varray()); bind_string_method(validate_node_name, sarray(), varray()); + bind_string_method(validate_filename, sarray(), varray()); bind_string_method(is_valid_identifier, sarray(), varray()); bind_string_method(is_valid_int, sarray(), varray()); |