summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-10-13 15:24:18 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-10-13 15:24:18 +0200
commitf12c4e8b9a2fcd159c8ee0aa2c76eb274d936883 (patch)
treea35549d218c2f71b582a16f452070a21f4637b1a /core
parent29fc755f5b93f75660c86f337dce1443197a3d5d (diff)
parentbf1a40c168b415925dd74bee6be5e41adb79b185 (diff)
Merge pull request #67251 from groud/simplify_path_solve_urls
Make String.simplify_path keep the protocol identifier for urls
Diffstat (limited to 'core')
-rw-r--r--core/string/ustring.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 872c8357ae..671b06f0ed 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -3667,32 +3667,43 @@ bool String::is_network_share_path() const {
String String::simplify_path() const {
String s = *this;
String drive;
- if (s.begins_with("local://")) {
- drive = "local://";
- s = s.substr(8);
- } else if (s.begins_with("res://")) {
- drive = "res://";
- s = s.substr(6);
- } else if (s.begins_with("user://")) {
- drive = "user://";
- s = s.substr(7);
- } else if (s.begins_with("uid://")) {
- drive = "uid://";
- s = s.substr(6);
- } else if (is_network_share_path()) {
- drive = s.substr(0, 2);
- s = s.substr(2, s.length() - 2);
- } else if (s.begins_with("/") || s.begins_with("\\")) {
- drive = s.substr(0, 1);
- s = s.substr(1, s.length() - 1);
- } else {
- int p = s.find(":/");
- if (p == -1) {
- p = s.find(":\\");
+
+ // Check if we have a special path (like res://) or a protocol identifier.
+ int p = s.find("://");
+ bool found = false;
+ if (p > 0) {
+ bool only_chars = true;
+ for (int i = 0; i < p; i++) {
+ if (!is_ascii_char(s[i])) {
+ only_chars = false;
+ break;
+ }
+ }
+ if (only_chars) {
+ found = true;
+ drive = s.substr(0, p + 3);
+ s = s.substr(p + 3);
}
- if (p != -1 && p < s.find("/")) {
- drive = s.substr(0, p + 2);
- s = s.substr(p + 2);
+ }
+ if (!found) {
+ if (is_network_share_path()) {
+ // Network path, beginning with // or \\.
+ drive = s.substr(0, 2);
+ s = s.substr(2);
+ } else if (s.begins_with("/") || s.begins_with("\\")) {
+ // Absolute path.
+ drive = s.substr(0, 1);
+ s = s.substr(1);
+ } else {
+ // Windows-style drive path, like C:/ or C:\.
+ p = s.find(":/");
+ if (p == -1) {
+ p = s.find(":\\");
+ }
+ if (p != -1 && p < s.find("/")) {
+ drive = s.substr(0, p + 2);
+ s = s.substr(p + 2);
+ }
}
}