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

Commit64d6030

Browse files
committed
Added an improvement to the equality operation to be able to compare the URI query, independently of the order of the URI query arguments.
1 parente874ef6 commit64d6030

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

‎include/network/uri/uri.hpp‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,29 +312,31 @@ std::size_t hash_value(const uri &uri_)
312312
return seed;
313313
}
314314

315-
inline
316-
booloperator == (const uri &lhs,const uri &rhs) {
317-
returnboost::equal(lhs, rhs);
318-
}
315+
//inline
316+
//bool operator == (const uri &lhs, const uri &rhs) {
317+
// return boost::equal(lhs, rhs);
318+
//}
319+
320+
booloperator == (const uri &lhs,const uri &rhs);
319321

320322
inline
321323
booloperator == (const uri &lhs,const uri::string_type &rhs) {
322-
returnboost::equal(lhs,rhs);
324+
return lhs ==uri(rhs);
323325
}
324326

325327
inline
326328
booloperator == (const uri::string_type &lhs,const uri &rhs) {
327-
returnboost::equal(lhs,rhs);
329+
returnuri(lhs) ==rhs;
328330
}
329331

330332
inline
331333
booloperator == (const uri &lhs,const uri::value_type *rhs) {
332-
returnboost::equal(lhs,boost::as_literal(rhs));
334+
return lhs ==uri(rhs);
333335
}
334336

335337
inline
336338
booloperator == (const uri::value_type *lhs,const uri &rhs) {
337-
returnboost::equal(boost::as_literal(lhs),rhs);
339+
returnuri(lhs) ==rhs;
338340
}
339341

340342
inline

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,30 @@
55

66

77
#include<network/uri/uri.ipp>
8+
#include<network/uri/uri.hpp>
9+
#include<map>
10+
11+
#include<iterator>
12+
#include<iostream>
13+
14+
namespacenetwork {
15+
booloperator == (const uri &lhs,const uri &rhs) {
16+
bool equal =boost::equal(
17+
std::make_pair(std::begin(lhs.scheme_range()),std::begin(lhs.path_range())),
18+
std::make_pair(std::begin(rhs.scheme_range()),std::begin(rhs.path_range())));
19+
if (equal)
20+
{
21+
// TODO: test normalized paths
22+
equal =boost::equal(lhs.path_range(), rhs.path_range());
23+
}
24+
25+
if (equal)
26+
{
27+
// test query order
28+
std::map<uri::string_type, uri::string_type> lhs_query_params, rhs_query_params;
29+
equal = (query_map(lhs, lhs_query_params) ==query_map(rhs, rhs_query_params));
30+
}
31+
32+
return equal;
33+
}
34+
}// namespace network

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ BOOST_AUTO_TEST_CASE(equality_test_4) {
363363
BOOST_CHECK(uri_1.c_str() == uri_2);
364364
}
365365

366+
BOOST_AUTO_TEST_CASE(equality_test_reordered_query) {
367+
network::uriuri_1("http://www.example.com/?a=1&b=2");
368+
network::uriuri_2("http://www.example.com/?b=2&a=1");
369+
BOOST_CHECK(uri_1 == uri_2);
370+
}
371+
366372
BOOST_AUTO_TEST_CASE(inequality_test) {
367373
network::uriuri_1("http://www.example.com/");
368374
network::uriuri_2("http://www.example.com/");
@@ -454,6 +460,7 @@ BOOST_AUTO_TEST_CASE(issue_67_test) {
454460
}
455461

456462
BOOST_AUTO_TEST_CASE(from_parts_1) {
463+
std::cout << __FUNCTION__ << std::endl;
457464
BOOST_CHECK_EQUAL(network::uri("http://www.example.com/path?query#fragment"),
458465
network::from_parts(network::uri("http://www.example.com"),"/path","query","fragment"));
459466
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp