diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-04-30 23:02:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 23:02:51 +0200 |
commit | d12e0b6ef172fe6831df46efaf2046438f0e1340 (patch) | |
tree | 71210a18c84380b41b9888462c0333030a41865f /core/string | |
parent | 1202117e8f97f59dfbcabc7f0bb9daa002a3acd2 (diff) | |
parent | b6a21f85a74c01c6a297e9595900a25d29fd5dfb (diff) |
Merge pull request #48336 from bruvzg/fix_mixed_url_decode
Fix `url_decode` with mixed percent-encoding/Unicode strings.
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/ustring.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index c8d71c3236..a3bbb5ac18 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3784,27 +3784,28 @@ String String::uri_encode() const { } String String::uri_decode() const { - String res; - for (int i = 0; i < length(); ++i) { - if (unicode_at(i) == '%' && i + 2 < length()) { - char32_t ord1 = unicode_at(i + 1); + CharString src = utf8(); + CharString res; + for (int i = 0; i < src.length(); ++i) { + if (src[i] == '%' && i + 2 < src.length()) { + char ord1 = src[i + 1]; if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) { - char32_t ord2 = unicode_at(i + 2); + char ord2 = src[i + 2]; if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) { char bytes[3] = { (char)ord1, (char)ord2, 0 }; res += (char)strtol(bytes, nullptr, 16); i += 2; } } else { - res += unicode_at(i); + res += src[i]; } - } else if (unicode_at(i) == '+') { + } else if (src[i] == '+') { res += ' '; } else { - res += unicode_at(i); + res += src[i]; } } - return String::utf8(res.ascii()); + return String::utf8(res); } String String::c_unescape() const { |