Skip to content

Commit a0d2bc6

Browse files
committed
address pr reviews
1 parent 83effe3 commit a0d2bc6

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

include/ada/url_search_params-inl.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,9 @@ inline std::string url_search_params::to_string() const {
135135
}
136136

137137
inline std::string url_search_params::to_raw_string() const {
138-
auto character_set = ada::character_sets::QUERY_PERCENT_ENCODE;
139138
std::string out{};
140-
for (size_t i = 0; i < params.size(); i++) {
141-
auto key = ada::unicode::percent_encode(params[i].first, character_set);
142-
auto value = ada::unicode::percent_encode(params[i].second, character_set);
143-
144-
if (i != 0) {
139+
for (const auto &[key, value] : params) {
140+
if (!out.empty()) {
145141
out += "&";
146142
}
147143
out.append(key);

tests/ada_c.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,17 @@ TEST(ada_c, ada_search_params_to_raw_string) {
367367
ASSERT_EQ(convert_string(str), "a=b+c&d=e+f");
368368
ada_free_owned_string(str);
369369

370-
// to_raw_string preserves %20 encoding for spaces
370+
// to_raw_string outputs raw key/value without any encoding
371371
ada_owned_string raw_str = ada_search_params_to_raw_string(out);
372-
ASSERT_EQ(convert_string(raw_str), "a=b%20c&d=e%20f");
372+
ASSERT_EQ(convert_string(raw_str), "a=b c&d=e f");
373373
ada_free_owned_string(raw_str);
374374

375375
ada_free_search_params(out);
376376

377377
SUCCEED();
378378
}
379379

380-
TEST(ada_c, ada_search_params_to_raw_string_remove_preserves_encoding) {
381-
// Test the exact scenario from the issue
380+
TEST(ada_c, ada_search_params_to_raw_string_remove) {
382381
std::string input("a=%20&b=remove&c=2");
383382
auto params = ada_parse_search_params(input.c_str(), input.length());
384383

@@ -390,9 +389,9 @@ TEST(ada_c, ada_search_params_to_raw_string_remove_preserves_encoding) {
390389
ASSERT_EQ(convert_string(str), "a=+&c=2");
391390
ada_free_owned_string(str);
392391

393-
// to_raw_string preserves %20 encoding for spaces
392+
// to_raw_string outputs raw key/value without any encoding
394393
ada_owned_string raw_str = ada_search_params_to_raw_string(params);
395-
ASSERT_EQ(convert_string(raw_str), "a=%20&c=2");
394+
ASSERT_EQ(convert_string(raw_str), "a= &c=2");
396395
ada_free_owned_string(raw_str);
397396

398397
ada_free_search_params(params);

tests/url_search_params.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ TEST(url_search_params, to_raw_string_no_normalization) {
454454
params.append("a", "b c");
455455
// to_string normalizes space to +
456456
ASSERT_EQ(params.to_string(), "a=b+c");
457-
// to_raw_string preserves %20 encoding
458-
ASSERT_EQ(params.to_raw_string(), "a=b%20c");
457+
// to_raw_string outputs raw key/value without any encoding
458+
ASSERT_EQ(params.to_raw_string(), "a=b c");
459459
SUCCEED();
460460
}
461461

@@ -465,23 +465,22 @@ TEST(url_search_params, to_raw_string_with_special_chars) {
465465
params.append("key2", "another value");
466466
// to_string normalizes spaces to +
467467
ASSERT_EQ(params.to_string(), "key1=value+with+spaces&key2=another+value");
468-
// to_raw_string preserves %20 encoding
468+
// to_raw_string outputs raw key/value without any encoding
469469
ASSERT_EQ(params.to_raw_string(),
470-
"key1=value%20with%20spaces&key2=another%20value");
470+
"key1=value with spaces&key2=another value");
471471
SUCCEED();
472472
}
473473

474474
TEST(url_search_params, to_raw_string_with_accents) {
475475
auto params = ada::url_search_params();
476476
params.append("key1", "\u00E9t\u00E9");
477477
params.append("key2", "C\u00E9line Dion++");
478-
// Both should encode accents the same way
479-
// to_string normalizes spaces to +, to_raw_string uses %20
480-
// Note: + signs are not encoded by QUERY_PERCENT_ENCODE
478+
// to_string percent-encodes and normalizes spaces to +
481479
ASSERT_EQ(params.to_string(),
482480
"key1=%C3%A9t%C3%A9&key2=C%C3%A9line+Dion%2B%2B");
481+
// to_raw_string outputs raw key/value without any encoding
483482
ASSERT_EQ(params.to_raw_string(),
484-
"key1=%C3%A9t%C3%A9&key2=C%C3%A9line%20Dion++");
483+
"key1=\u00E9t\u00E9&key2=C\u00E9line Dion++");
485484
SUCCEED();
486485
}
487486

0 commit comments

Comments
 (0)