summaryrefslogtreecommitdiffstats
path: root/core/string/ustring.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-10-01 17:30:16 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-10-01 17:30:16 +0200
commitcf1d910e1052360d888a91851d44abf0a8273b6e (patch)
tree05e19a2b600a07004b6cb8d1693718cc771878a3 /core/string/ustring.cpp
parent8c16e67e4da9c5ce56d206e321bf2df23c35d064 (diff)
parent6516ca6b11a6241d7908eb322343d44c10050d98 (diff)
downloadredot-engine-cf1d910e1052360d888a91851d44abf0a8273b6e.tar.gz
Merge pull request #92237 from timothyqiu/url-fragment
String: Parse fragment from URL
Diffstat (limited to 'core/string/ustring.cpp')
-rw-r--r--core/string/ustring.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 391a203d5b..e6f7492a18 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -221,18 +221,35 @@ void CharString::copy_from(const char *p_cstr) {
/* String */
/*************************************************************************/
-Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const {
- // Splits the URL into scheme, host, port, path. Strip credentials when present.
+Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path, String &r_fragment) const {
+ // Splits the URL into scheme, host, port, path, fragment. Strip credentials when present.
String base = *this;
r_scheme = "";
r_host = "";
r_port = 0;
r_path = "";
+ r_fragment = "";
+
int pos = base.find("://");
// Scheme
if (pos != -1) {
- r_scheme = base.substr(0, pos + 3).to_lower();
- base = base.substr(pos + 3, base.length() - pos - 3);
+ bool is_scheme_valid = true;
+ for (int i = 0; i < pos; i++) {
+ if (!is_ascii_alphanumeric_char(base[i]) && base[i] != '+' && base[i] != '-' && base[i] != '.') {
+ is_scheme_valid = false;
+ break;
+ }
+ }
+ if (is_scheme_valid) {
+ r_scheme = base.substr(0, pos + 3).to_lower();
+ base = base.substr(pos + 3, base.length() - pos - 3);
+ }
+ }
+ pos = base.find("#");
+ // Fragment
+ if (pos != -1) {
+ r_fragment = base.substr(pos + 1);
+ base = base.substr(0, pos);
}
pos = base.find("/");
// Path