Skip to content

Commit 2eebc55

Browse files
committed
Added unit tests for encoded strings in URL.
1 parent e68ac19 commit 2eebc55

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

boost/network/uri/uri_accessors.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
# include <boost/network/uri/uri.hpp>
12+
# include <boost/network/uri/encode.hpp>
13+
# include <boost/network/uri/decode.hpp>
1214
# include <boost/spirit/include/qi.hpp>
1315

1416

@@ -80,6 +82,16 @@ typename basic_uri<Tag>::string_type password(const basic_uri<Tag> &uri) {
8082
}
8183
return typename string<Tag>::type(it, boost::end(user_info_range));
8284
}
85+
86+
template <
87+
class Tag
88+
>
89+
typename basic_uri<Tag>::string_type decoded_path(const basic_uri<Tag> &uri) {
90+
typename basic_uri<Tag>::const_range_type path_range = uri.path_range();
91+
typename basic_uri<Tag>::string_type decoded_path;
92+
decode(path_range, std::back_inserter(decoded_path));
93+
return decoded_path;
94+
}
8395
} // namespace uri
8496
} // namespace network
8597
} // namespace boost

libs/network/test/uri/url_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,18 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(encoded_uri_test, T, tag_types) {
201201
typedef uri::basic_uri<T> uri_type;
202202
typedef typename uri_type::string_type string_type;
203203

204-
const std::string url("http://www.example.com/");
204+
const std::string url("http://www.example.com/Path%20With%20%28Some%29%20Encoded%20Characters%21");
205205
const std::string scheme("http");
206206
const std::string host("www.example.com");
207-
const std::string path("/");
207+
const std::string encoded_path("/Path%20With%20%28Some%29%20Encoded%20Characters%21");
208+
const std::string decoded_path("/Path With (Some) Encoded Characters!");
208209

209210
uri_type instance(string_type(boost::begin(url), boost::end(url)));
210211
BOOST_REQUIRE(uri::is_valid(instance));
211212
BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
212213
BOOST_CHECK(boost::equal(uri::host(instance), host));
213-
BOOST_CHECK(boost::equal(uri::path(instance), path));
214+
BOOST_CHECK(boost::equal(uri::path(instance), encoded_path));
215+
BOOST_CHECK(boost::equal(uri::decoded_path(instance), decoded_path));
214216
}
215217

216218
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor_test, T, tag_types) {

0 commit comments

Comments
 (0)