Skip to content

Commit bad7fd7

Browse files
committed
fix: replace spaces with plus character
1 parent d08c2c9 commit bad7fd7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/ada/character_sets-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ constexpr uint8_t WWW_FORM_URLENCODED_PERCENT_ENCODE[32] = {
517517
// 18 19 1A 1B 1C 1D 1E 1F
518518
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
519519
// 20 21 22 23 24 25 26 27
520-
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
520+
0x00 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
521521
// 28 29 2A 2B 2C 2D 2E 2F
522522
0x01 | 0x02 | 0x00 | 0x08 | 0x10 | 0x00 | 0x00 | 0x00,
523523
// 30 31 32 33 34 35 36 37

include/ada/url_search_params-inl.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ inline std::string url_search_params::to_string() {
6060
auto character_set = ada::character_sets::WWW_FORM_URLENCODED_PERCENT_ENCODE;
6161
std::string out{};
6262
for (size_t i = 0; i < params.size(); i++) {
63-
auto [key, value] = params[i];
63+
auto key = ada::unicode::percent_encode(params[i].first, character_set);
64+
auto value = ada::unicode::percent_encode(params[i].second, character_set);
65+
66+
// Performance optimization: Move this inside percent_encode.
67+
std::replace(key.begin(), key.end(), ' ', '+');
68+
std::replace(value.begin(), value.end(), ' ', '+');
6469

6570
if (i != 0) {
6671
out += "&";
6772
}
68-
out.append(ada::unicode::percent_encode(key, character_set));
73+
out.append(key);
6974
out += "=";
70-
out.append(ada::unicode::percent_encode(value, character_set));
75+
out.append(value);
7176
}
7277
return out;
7378
}

0 commit comments

Comments
 (0)