Fix localize_path with custom protocol identifiers

This commit is contained in:
Gilles Roudière 2022-10-19 18:23:20 +02:00
parent 61051a44cc
commit 56fa8f1d58
2 changed files with 18 additions and 3 deletions

View File

@ -153,8 +153,23 @@ const PackedStringArray ProjectSettings::_trim_to_supported_features(const Packe
#endif // TOOLS_ENABLED #endif // TOOLS_ENABLED
String ProjectSettings::localize_path(const String &p_path) const { String ProjectSettings::localize_path(const String &p_path) const {
if (resource_path.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") || if (resource_path.is_empty() || (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) {
(p_path.is_absolute_path() && !p_path.begins_with(resource_path))) { return p_path.simplify_path();
}
// Check if we have a special path (like res://) or a protocol identifier.
int p = p_path.find("://");
bool found = false;
if (p > 0) {
found = true;
for (int i = 0; i < p; i++) {
if (!is_ascii_alphanumeric_char(p_path[i])) {
found = false;
break;
}
}
}
if (found) {
return p_path.simplify_path(); return p_path.simplify_path();
} }

View File

@ -3675,7 +3675,7 @@ String String::simplify_path() const {
if (p > 0) { if (p > 0) {
bool only_chars = true; bool only_chars = true;
for (int i = 0; i < p; i++) { for (int i = 0; i < p; i++) {
if (!is_ascii_char(s[i])) { if (!is_ascii_alphanumeric_char(s[i])) {
only_chars = false; only_chars = false;
break; break;
} }