Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita127593

Browse files
committed
Updated equality test to take into account if the default port is specified.
1 parent72f94ec commita127593

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

‎libs/network/src/uri/uri.cpp‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,40 @@ namespace network {
1616
booloperator == (const uri &lhs,const uri &rhs) {
1717
// the scheme can be compared insensitive to case
1818
bool equal =boost::iequals(lhs.scheme_range(), rhs.scheme_range());
19-
if (equal)
20-
{
19+
if (equal) {
2120
// the user info must be case sensitive
2221
equal =boost::equals(lhs.user_info_range(), rhs.user_info_range());
2322
}
2423

25-
if (equal)
26-
{
24+
if (equal){
2725
// the host can be compared insensitive to case
28-
equal =boost::iequals(
29-
std::make_pair(std::begin(lhs.host_range()),std::end(lhs.host_range())),
30-
std::make_pair(std::begin(rhs.host_range()),std::end(rhs.host_range())));
26+
equal =boost::iequals(lhs.host_range(), rhs.host_range());
3127
}
3228

33-
if (equal)
34-
{
35-
// TODO: test default ports according to scheme
36-
equal =boost::equals(
37-
std::make_pair(std::begin(lhs.port_range()),std::end(lhs.port_range())),
38-
std::make_pair(std::begin(rhs.port_range()),std::end(rhs.port_range())));
29+
if (equal) {
30+
if (lhs.port_range() && rhs.port_range()) {
31+
equal =boost::equals(lhs.port_range(), rhs.port_range());
32+
}
33+
elseif (!lhs.port_range() && rhs.port_range()) {
34+
auto port =default_port(lhs.scheme());
35+
if (port) {
36+
equal =boost::equals(*port, rhs.port_range());
37+
}
38+
}
39+
elseif (lhs.port_range() && !rhs.port_range()) {
40+
auto port =default_port(rhs.scheme());
41+
if (port) {
42+
equal =boost::equals(lhs.port_range(), *port);
43+
}
44+
}
3945
}
4046

41-
if (equal)
42-
{
47+
if (equal) {
4348
// TODO: test normalized paths
4449
equal =boost::iequals(lhs.path_range(), rhs.path_range());
4550
}
4651

47-
if (equal)
48-
{
52+
if (equal) {
4953
// test query, independent of order
5054
std::map<uri::string_type, uri::string_type> lhs_query_params, rhs_query_params;
5155
equal = (query_map(lhs, lhs_query_params) ==query_map(rhs, rhs_query_params));

‎libs/network/test/uri/uri_test.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,30 @@ BOOST_AUTO_TEST_CASE(equality_test_user_info) {
387387
BOOST_CHECK(uri_1 != uri_2);
388388
}
389389

390+
BOOST_AUTO_TEST_CASE(equality_test_default_http_port) {
391+
network::uriuri_1("http://www.example.com/");
392+
network::uriuri_2("http://www.example.com:80/");
393+
BOOST_CHECK(uri_1 == uri_2);
394+
}
395+
396+
BOOST_AUTO_TEST_CASE(equality_test_default_http_port_2) {
397+
network::uriuri_1("http://www.example.com:80/");
398+
network::uriuri_2("http://www.example.com/");
399+
BOOST_CHECK(uri_1 == uri_2);
400+
}
401+
402+
BOOST_AUTO_TEST_CASE(equality_test_default_https_port) {
403+
network::uriuri_1("https://www.example.com/");
404+
network::uriuri_2("https://www.example.com:443/");
405+
BOOST_CHECK(uri_1 == uri_2);
406+
}
407+
408+
BOOST_AUTO_TEST_CASE(equality_test_default_https_port_2) {
409+
network::uriuri_1("https://www.example.com:443/");
410+
network::uriuri_2("https://www.example.com/");
411+
BOOST_CHECK(uri_1 == uri_2);
412+
}
413+
390414
BOOST_AUTO_TEST_CASE(inequality_test) {
391415
network::uriuri_1("http://www.example.com/");
392416
network::uriuri_2("http://www.example.com/");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp