Skip to content

Commit dcf8721

Browse files
committed
Applied feedback from review
1 parent 6c9b993 commit dcf8721

File tree

6 files changed

+30
-33
lines changed

6 files changed

+30
-33
lines changed

include/network/uri/detail/encode.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ OutputIterator encode_path(InputIterator first, InputIterator last,
105105
return out;
106106
}
107107

108-
template <typename InputIterator, typename OutputIterator>
109-
OutputIterator encode_query(InputIterator first, InputIterator last,
110-
OutputIterator out) {
111-
auto it = first;
112-
while (it != last) {
113-
detail::encode_char(*it, out, "/.@&%;");
114-
++it;
115-
}
116-
return out;
117-
}
118-
119108
template <typename InputIterator, typename OutputIterator>
120109
OutputIterator encode_query_component(InputIterator first, InputIterator last,
121110
OutputIterator out) {
@@ -167,13 +156,6 @@ String encode_path(const String &path) {
167156
return encoded;
168157
}
169158

170-
template <class String>
171-
String encode_query(const String &query) {
172-
String encoded;
173-
encode_query(std::begin(query), std::end(query), std::back_inserter(encoded));
174-
return encoded;
175-
}
176-
177159
template <class String>
178160
String encode_fragment(const String &fragment) {
179161
String encoded;

include/network/uri/uri.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class uri {
560560
template <typename InputIter, typename OutputIter>
561561
static OutputIter encode_query(InputIter first, InputIter last,
562562
OutputIter out) {
563-
return detail::encode_query(first, last, out);
563+
return detail::encode_query_component(first, last, out);
564564
}
565565

566566
/**

include/network/uri/uri_builder.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ class uri_builder {
198198
/**
199199
* \brief Adds a new query value to the uri_builder. The '='
200200
* symbol is percent encoded.
201-
* \param parameter The query parameter.
201+
* \param name The query parameter.
202202
* \returns \c *this
203203
* \sa append_query_key_value_pair
204204
*/
205205
template <typename Source>
206-
uri_builder &append_query_parameter(const Source &parameter) {
207-
append_query_parameter(detail::translate(parameter));
206+
uri_builder &append_query_parameter(const Source &name) {
207+
append_query_parameter(detail::translate(name));
208208
return *this;
209209
}
210210

@@ -261,7 +261,7 @@ class uri_builder {
261261
void set_port(string_type port);
262262
void set_authority(string_type authority);
263263
void set_path(string_type path);
264-
void append_query_parameter(string_type query);
264+
void append_query_parameter(string_type name);
265265
void append_query_key_value_pair(string_type key, string_type value);
266266
void set_fragment(string_type fragment);
267267

src/uri_builder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
namespace network {
1313
uri_builder::uri_builder(const network::uri &base_uri) {
1414
if (base_uri.has_scheme()) {
15-
set_scheme(base_uri.scheme().to_string());
15+
scheme_ = base_uri.scheme().to_string();
1616
}
1717

1818
if (base_uri.has_user_info()) {
19-
set_user_info(base_uri.user_info().to_string());
19+
user_info_ = base_uri.user_info().to_string();
2020
}
2121

2222
if (base_uri.has_host()) {
23-
set_host(base_uri.host().to_string());
23+
host_ = base_uri.host().to_string();
2424
}
2525

2626
if (base_uri.has_port()) {
27-
set_port(base_uri.port().to_string());
27+
port_ = base_uri.port().to_string();
2828
}
2929

3030
if (base_uri.has_path()) {
31-
set_path(base_uri.path().to_string());
31+
path_ = base_uri.path().to_string();
3232
}
3333

3434
if (base_uri.has_query()) {
35-
append_query_parameter(base_uri.query().to_string());
35+
query_ = base_uri.query().to_string();
3636
}
3737

3838
if (base_uri.has_fragment()) {
39-
set_fragment(base_uri.fragment().to_string());
39+
fragment_ = base_uri.fragment().to_string();
4040
}
4141
}
4242

@@ -111,14 +111,14 @@ uri_builder &uri_builder::clear_path() {
111111
return *this;
112112
}
113113

114-
void uri_builder::append_query_parameter(string_type query) {
114+
void uri_builder::append_query_parameter(string_type name) {
115115
if (!query_) {
116116
query_ = string_type();
117117
}
118118
else {
119119
query_->append("&");
120120
}
121-
network::uri::encode_query(std::begin(query), std::end(query),
121+
network::uri::encode_query(std::begin(name), std::end(name),
122122
std::back_inserter(*query_));
123123
}
124124

test/uri_builder_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,18 @@ TEST(builder_test, append_query_key_value_pair_does_not_encode_qmark) {
838838
ASSERT_NO_THROW(ub.append_query_key_value_pair("q", "?"));
839839
ASSERT_EQ(network::string_view("?"), ub.uri().query_begin()->second);
840840
}
841+
842+
TEST(builder_test, build_from_uri_with_encoded_user_info) {
843+
network::uri_builder ub(network::uri("http://%[email protected]"));
844+
ASSERT_EQ(network::string_view("%40"), ub.uri().user_info());
845+
}
846+
847+
TEST(builder_test, build_from_uri_with_encoded_query) {
848+
network::uri_builder ub(network::uri("http://example.com?x=%40"));
849+
ASSERT_EQ(network::string_view("x=%40"), ub.uri().query());
850+
}
851+
852+
TEST(builder_test, build_from_uri_with_encoded_fragment) {
853+
network::uri_builder ub(network::uri("http://example.com#%40"));
854+
ASSERT_EQ(network::string_view("%40"), ub.uri().fragment());
855+
}

test/uri_encoding_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST(uri_encoding_test, encode_query_iterator) {
5454
std::string instance;
5555
network::uri::encode_query(std::begin(unencoded), std::end(unencoded),
5656
std::back_inserter(instance));
57-
ASSERT_EQ("%21%23%24&%27%28%29%2A%2B%2C/%3A;%3D%3F@%5B%5D", instance);
57+
ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D?%40%5B%5D", instance);
5858
}
5959

6060
TEST(uri_encoding_test, encode_fragment_iterator) {

0 commit comments

Comments
 (0)