Skip to content

Commit 992c714

Browse files
committed
common: Don't terminate on null character in UrlDecode
The previous behavior was the result of casting the result returned from the libevent function evhttp_uridecode to std:string but this was probably not intended.
1 parent 099fa57 commit 992c714

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/common/url.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ std::string UrlDecode(std::string_view url_encoded)
2525
// Only if there is no error and the pointer is set to the end of
2626
// the string, we can be sure both characters were valid hex
2727
if (ec == std::errc{} && p == url_encoded.data() + i + 3) {
28-
// A null character terminates the string
29-
if (decoded_value == 0) {
30-
return res;
31-
}
32-
3328
res += static_cast<char>(decoded_value);
3429
// Next two characters are part of the percent encoding
3530
i += 2;

src/test/common_url_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ BOOST_AUTO_TEST_CASE(decode_lowercase_hex_test) {
6363
}
6464

6565
BOOST_AUTO_TEST_CASE(decode_internal_nulls_test) {
66-
BOOST_CHECK_EQUAL(UrlDecode("%00%00x%00%00"), "");
67-
BOOST_CHECK_EQUAL(UrlDecode("abc%00%00"), "abc");
66+
std::string result1{"\0\0x\0\0", 5};
67+
BOOST_CHECK_EQUAL(UrlDecode("%00%00x%00%00"), result1);
68+
std::string result2{"abc\0\0", 5};
69+
BOOST_CHECK_EQUAL(UrlDecode("abc%00%00"), result2);
6870
}
6971

7072
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)