summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGilles Roudière <gilles.roudiere@gmail.com>2022-10-11 14:40:12 +0200
committerGilles Roudière <gilles.roudiere@gmail.com>2022-10-13 12:23:49 +0200
commitbf1a40c168b415925dd74bee6be5e41adb79b185 (patch)
tree6af7b6408ab5be6f999aeaa3677829ab31a6d4cd /core
parent5aadc618b6ff152dbc0ca4ea901c34a97e164091 (diff)
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);
+ }
}
}