Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix uri decoding with lower case digits

HolonProduction671d85c38e6f
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 2e1c65805f5..94d9a06b07f 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4427,9 +4427,9 @@ String String::uri_decode() const {
for (int i = 0; i < src.length(); ++i) {
if (src[i] == '%' && i + 2 < src.length()) {
char ord1 = src[i + 1];
- if (is_digit(ord1) || is_ascii_upper_case(ord1)) {
+ if (is_hex_digit(ord1)) {
char ord2 = src[i + 2];
- if (is_digit(ord2) || is_ascii_upper_case(ord2)) {
+ if (is_hex_digit(ord2)) {
char bytes[3] = { (char)ord1, (char)ord2, 0 };
res += (char)strtol(bytes, nullptr, 16);
i += 2;
@@ -4452,9 +4452,9 @@ String String::uri_file_decode() const {
for (int i = 0; i < src.length(); ++i) {
if (src[i] == '%' && i + 2 < src.length()) {
char ord1 = src[i + 1];
- if (is_digit(ord1) || is_ascii_upper_case(ord1)) {
+ if (is_hex_digit(ord1)) {
char ord2 = src[i + 2];
- if (is_digit(ord2) || is_ascii_upper_case(ord2)) {
+ if (is_hex_digit(ord2)) {
char bytes[3] = { (char)ord1, (char)ord2, 0 };
res += (char)strtol(bytes, nullptr, 16);
i += 2;
diff --git a/tests/core/string/test_string.cpp b/tests/core/string/test_string.cpp
index 37f9f128eb3..11fb18db422 100644
--- a/tests/core/string/test_string.cpp
+++ b/tests/core/string/test_string.cpp
@@ -1901,6 +1901,7 @@ TEST_CASE("[String] uri_encode/unescape") {
String x2 = String::utf8((const char *)u8str);
String x3 = U"Tēšt";
String x4 = U"file+name";
+ String x5 = U"%5B%5b+%5d%5D";
CHECK(x1.uri_decode() == x2);
CHECK(x1.uri_decode() == x3);
@@ -1912,6 +1913,8 @@ TEST_CASE("[String] uri_encode/unescape") {
CHECK(t.uri_decode() == s);
CHECK(x4.uri_file_decode() == x4);
CHECK(x4.uri_decode() == U"file name");
+ CHECK(x5.uri_file_decode() == U"[[+]]");
+ CHECK(x5.uri_decode() == U"[[ ]]");
}
TEST_CASE("[String] xml_escape/unescape") {