summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTheraot <Theraot@gmail.com>2021-08-23 22:32:13 -0500
committerTheraot <Theraot@gmail.com>2021-08-24 04:16:59 -0500
commitef54d35395d3b75cf3189c33cd2d2a096a3ad4a1 (patch)
treec6fddb06d62af2d90416276094645c8ccb986d6b /core
parent13bd020a23008cd4e51be21865c620e12e3b3ded (diff)
Fix get_base_dir windows top level directory logic
This is a fix for https://github.com/godotengine/godot/issues/52048
Diffstat (limited to 'core')
-rw-r--r--core/string/ustring.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index a30d6b9102..2390d007db 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4329,23 +4329,39 @@ bool String::is_rel_path() const {
}
String String::get_base_dir() const {
- int basepos = find(":/");
- if (basepos == -1) {
- basepos = find(":\\");
+ int end = 0;
+
+ // url scheme style base
+ int basepos = find("://");
+ if (basepos != -1) {
+ end = basepos + 3;
}
+
+ // windows top level directory base
+ if (end == 0) {
+ basepos = find(":/");
+ if (basepos == -1) {
+ basepos = find(":\\");
+ }
+ if (basepos != -1) {
+ end = basepos + 2;
+ }
+ }
+
+ // unix root directory base
+ if (end == 0) {
+ if (begins_with("/")) {
+ end = 1;
+ }
+ }
+
String rs;
String base;
- if (basepos != -1) {
- int end = basepos + 3;
+ if (end != 0) {
rs = substr(end, length());
base = substr(0, end);
} else {
- if (begins_with("/")) {
- rs = substr(1, length());
- base = "/";
- } else {
- rs = *this;
- }
+ rs = *this;
}
int sep = MAX(rs.rfind("/"), rs.rfind("\\"));