Skip to content

Commit 099fa57

Browse files
committed
scripted-diff: Modernize name of urlDecode function and param
-BEGIN VERIFY SCRIPT- sed -i 's/urlDecode/UrlDecode/g' $(git grep -l 'urlDecode' ./src) sed -i 's/urlEncoded/url_encoded/g' $(git grep -l 'urlEncoded' ./src) -END VERIFY SCRIPT-
1 parent 8f39aaa commit 099fa57

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

src/common/url.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
#include <string_view>
1010
#include <system_error>
1111

12-
std::string urlDecode(std::string_view urlEncoded)
12+
std::string UrlDecode(std::string_view url_encoded)
1313
{
1414
std::string res;
15-
res.reserve(urlEncoded.size());
15+
res.reserve(url_encoded.size());
1616

17-
for (size_t i = 0; i < urlEncoded.size(); ++i) {
18-
char c = urlEncoded[i];
17+
for (size_t i = 0; i < url_encoded.size(); ++i) {
18+
char c = url_encoded[i];
1919
// Special handling for percent which should be followed by two hex digits
2020
// representing an octet values, see RFC 3986, Section 2.1 Percent-Encoding
21-
if (c == '%' && i + 2 < urlEncoded.size()) {
21+
if (c == '%' && i + 2 < url_encoded.size()) {
2222
unsigned int decoded_value{0};
23-
auto [p, ec] = std::from_chars(urlEncoded.data() + i + 1, urlEncoded.data() + i + 3, decoded_value, 16);
23+
auto [p, ec] = std::from_chars(url_encoded.data() + i + 1, url_encoded.data() + i + 3, decoded_value, 16);
2424

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
27-
if (ec == std::errc{} && p == urlEncoded.data() + i + 3) {
27+
if (ec == std::errc{} && p == url_encoded.data() + i + 3) {
2828
// A null character terminates the string
2929
if (decoded_value == 0) {
3030
return res;

src/common/url.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
*
1313
* Notably this implementation does not decode a '+' to a ' '.
1414
*/
15-
std::string urlDecode(std::string_view url_encoded);
15+
std::string UrlDecode(std::string_view url_encoded);
1616

1717
#endif // BITCOIN_COMMON_URL_H

src/test/common_url_tests.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,60 @@
1111
BOOST_AUTO_TEST_SUITE(common_url_tests)
1212

1313
// These test vectors were ported from test/regress.c in the libevent library
14-
// which used to be a dependency of the urlDecode function.
14+
// which used to be a dependency of the UrlDecode function.
1515

1616
BOOST_AUTO_TEST_CASE(encode_decode_test) {
17-
BOOST_CHECK_EQUAL(urlDecode("Hello"), "Hello");
18-
BOOST_CHECK_EQUAL(urlDecode("99"), "99");
19-
BOOST_CHECK_EQUAL(urlDecode(""), "");
20-
BOOST_CHECK_EQUAL(urlDecode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_"),
17+
BOOST_CHECK_EQUAL(UrlDecode("Hello"), "Hello");
18+
BOOST_CHECK_EQUAL(UrlDecode("99"), "99");
19+
BOOST_CHECK_EQUAL(UrlDecode(""), "");
20+
BOOST_CHECK_EQUAL(UrlDecode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_"),
2121
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_");
22-
BOOST_CHECK_EQUAL(urlDecode("%20"), " ");
23-
BOOST_CHECK_EQUAL(urlDecode("%FF%F0%E0"), "\xff\xf0\xe0");
24-
BOOST_CHECK_EQUAL(urlDecode("%01%19"), "\x01\x19");
25-
BOOST_CHECK_EQUAL(urlDecode("http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3986.txt"),
22+
BOOST_CHECK_EQUAL(UrlDecode("%20"), " ");
23+
BOOST_CHECK_EQUAL(UrlDecode("%FF%F0%E0"), "\xff\xf0\xe0");
24+
BOOST_CHECK_EQUAL(UrlDecode("%01%19"), "\x01\x19");
25+
BOOST_CHECK_EQUAL(UrlDecode("http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3986.txt"),
2626
"http://www.ietf.org/rfc/rfc3986.txt");
27-
BOOST_CHECK_EQUAL(urlDecode("1%2B2%3D3"), "1+2=3");
27+
BOOST_CHECK_EQUAL(UrlDecode("1%2B2%3D3"), "1+2=3");
2828
}
2929

3030
BOOST_AUTO_TEST_CASE(decode_malformed_test) {
31-
BOOST_CHECK_EQUAL(urlDecode("%%xhello th+ere \xff"), "%%xhello th+ere \xff");
31+
BOOST_CHECK_EQUAL(UrlDecode("%%xhello th+ere \xff"), "%%xhello th+ere \xff");
3232

33-
BOOST_CHECK_EQUAL(urlDecode("%"), "%");
34-
BOOST_CHECK_EQUAL(urlDecode("%%"), "%%");
35-
BOOST_CHECK_EQUAL(urlDecode("%%%"), "%%%");
36-
BOOST_CHECK_EQUAL(urlDecode("%%%%"), "%%%%");
33+
BOOST_CHECK_EQUAL(UrlDecode("%"), "%");
34+
BOOST_CHECK_EQUAL(UrlDecode("%%"), "%%");
35+
BOOST_CHECK_EQUAL(UrlDecode("%%%"), "%%%");
36+
BOOST_CHECK_EQUAL(UrlDecode("%%%%"), "%%%%");
3737

38-
BOOST_CHECK_EQUAL(urlDecode("+"), "+");
39-
BOOST_CHECK_EQUAL(urlDecode("++"), "++");
38+
BOOST_CHECK_EQUAL(UrlDecode("+"), "+");
39+
BOOST_CHECK_EQUAL(UrlDecode("++"), "++");
4040

41-
BOOST_CHECK_EQUAL(urlDecode("?"), "?");
42-
BOOST_CHECK_EQUAL(urlDecode("??"), "??");
41+
BOOST_CHECK_EQUAL(UrlDecode("?"), "?");
42+
BOOST_CHECK_EQUAL(UrlDecode("??"), "??");
4343

44-
BOOST_CHECK_EQUAL(urlDecode("%G1"), "%G1");
45-
BOOST_CHECK_EQUAL(urlDecode("%2"), "%2");
46-
BOOST_CHECK_EQUAL(urlDecode("%ZX"), "%ZX");
44+
BOOST_CHECK_EQUAL(UrlDecode("%G1"), "%G1");
45+
BOOST_CHECK_EQUAL(UrlDecode("%2"), "%2");
46+
BOOST_CHECK_EQUAL(UrlDecode("%ZX"), "%ZX");
4747

48-
BOOST_CHECK_EQUAL(urlDecode("valid%20string%G1"), "valid string%G1");
49-
BOOST_CHECK_EQUAL(urlDecode("%20invalid%ZX"), " invalid%ZX");
50-
BOOST_CHECK_EQUAL(urlDecode("%20%G1%ZX"), " %G1%ZX");
48+
BOOST_CHECK_EQUAL(UrlDecode("valid%20string%G1"), "valid string%G1");
49+
BOOST_CHECK_EQUAL(UrlDecode("%20invalid%ZX"), " invalid%ZX");
50+
BOOST_CHECK_EQUAL(UrlDecode("%20%G1%ZX"), " %G1%ZX");
5151

52-
BOOST_CHECK_EQUAL(urlDecode("%1 "), "%1 ");
53-
BOOST_CHECK_EQUAL(urlDecode("% 9"), "% 9");
54-
BOOST_CHECK_EQUAL(urlDecode(" %Z "), " %Z ");
55-
BOOST_CHECK_EQUAL(urlDecode(" % X"), " % X");
52+
BOOST_CHECK_EQUAL(UrlDecode("%1 "), "%1 ");
53+
BOOST_CHECK_EQUAL(UrlDecode("% 9"), "% 9");
54+
BOOST_CHECK_EQUAL(UrlDecode(" %Z "), " %Z ");
55+
BOOST_CHECK_EQUAL(UrlDecode(" % X"), " % X");
5656

57-
BOOST_CHECK_EQUAL(urlDecode("%-1"), "%-1");
58-
BOOST_CHECK_EQUAL(urlDecode("%1-"), "%1-");
57+
BOOST_CHECK_EQUAL(UrlDecode("%-1"), "%-1");
58+
BOOST_CHECK_EQUAL(UrlDecode("%1-"), "%1-");
5959
}
6060

6161
BOOST_AUTO_TEST_CASE(decode_lowercase_hex_test) {
62-
BOOST_CHECK_EQUAL(urlDecode("%f0%a0%b0"), "\xf0\xa0\xb0");
62+
BOOST_CHECK_EQUAL(UrlDecode("%f0%a0%b0"), "\xf0\xa0\xb0");
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+
BOOST_CHECK_EQUAL(UrlDecode("%00%00x%00%00"), "");
67+
BOOST_CHECK_EQUAL(UrlDecode("abc%00%00"), "abc");
6868
}
6969

7070
BOOST_AUTO_TEST_SUITE_END()

src/test/fuzz/string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ FUZZ_TARGET(string)
9090
(void)ToUpper(random_string_1);
9191
(void)TrimString(random_string_1);
9292
(void)TrimString(random_string_1, random_string_2);
93-
(void)urlDecode(random_string_1);
93+
(void)UrlDecode(random_string_1);
9494
(void)ContainsNoNUL(random_string_1);
9595
(void)_(random_string_1.c_str());
9696
try {

src/wallet/rpc/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string&
6464
{
6565
if (request.URI.starts_with(WALLET_ENDPOINT_BASE)) {
6666
// wallet endpoint was used
67-
wallet_name = urlDecode(std::string_view{request.URI}.substr(WALLET_ENDPOINT_BASE.size()));
67+
wallet_name = UrlDecode(std::string_view{request.URI}.substr(WALLET_ENDPOINT_BASE.size()));
6868
return true;
6969
}
7070
return false;

0 commit comments

Comments
 (0)