Skip to content

Commit 302c717

Browse files
committed
[uri] Fixed issue cpp-netlib#104.
1 parent eef48fa commit 302c717

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

boost/network/uri/uri.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,17 @@ class BOOST_URI_DECL uri {
5959
}
6060

6161
uri(const uri &other)
62-
: uri_(other.uri_),
63-
uri_parts_(other.uri_parts_),
64-
is_valid_(other.is_valid_) {
65-
62+
: uri_(other.uri_) {
63+
parse();
6664
}
6765

6866
uri &operator = (const uri &other) {
6967
uri(other).swap(*this);
7068
return *this;
7169
}
7270

73-
uri &operator = (const string_type &uri) {
74-
uri_ = uri;
75-
parse();
71+
uri &operator = (const string_type &uri_string) {
72+
uri(uri_string).swap(*this);
7673
return *this;
7774
}
7875

@@ -82,7 +79,8 @@ class BOOST_URI_DECL uri {
8279

8380
void swap(uri &other) {
8481
boost::swap(uri_, other.uri_);
85-
parse();
82+
boost::swap(uri_parts_, other.uri_parts_);
83+
boost::swap(is_valid_, other.is_valid_);
8684
}
8785

8886
const_iterator begin() const {

libs/network/test/uri/uri_test.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/network/uri/uri.hpp>
1111
#include <boost/network/uri/uri_io.hpp>
1212
#include <boost/range/algorithm/equal.hpp>
13+
#include <boost/scoped_ptr.hpp>
1314
#include <map>
1415

1516

@@ -397,16 +398,15 @@ BOOST_AUTO_TEST_CASE(xmpp_query_map_test) {
397398
BOOST_CHECK_EQUAL((++queries.begin())->second, "Hello%20World");
398399
}
399400

400-
BOOST_AUTO_TEST_CASE(range_test)
401-
{
401+
BOOST_AUTO_TEST_CASE(range_test) {
402402
const std::string url("http://www.example.com/");
403403
uri::uri instance(url);
404404
BOOST_REQUIRE(uri::valid(instance));
405405
BOOST_CHECK(boost::equal(instance, url));
406406
}
407407

408-
BOOST_AUTO_TEST_CASE(issue_67_test)
409-
{
408+
BOOST_AUTO_TEST_CASE(issue_67_test) {
409+
// https://github.com/cpp-netlib/cpp-netlib/issues/67
410410
const std::string site_name("http://www.google.com");
411411
uri::uri bar0;
412412
uri::uri bar1 = site_name;
@@ -415,32 +415,35 @@ BOOST_AUTO_TEST_CASE(issue_67_test)
415415
BOOST_CHECK(uri::is_valid(bar1));
416416
}
417417

418-
BOOST_AUTO_TEST_CASE(from_parts_1)
419-
{
418+
BOOST_AUTO_TEST_CASE(from_parts_1) {
420419
BOOST_CHECK_EQUAL(uri::uri("http://www.example.com/path?query#fragment"),
421420
uri::from_parts(uri::uri("http://www.example.com"), "/path", "query", "fragment"));
422421
}
423422

424-
BOOST_AUTO_TEST_CASE(from_parts_2)
425-
{
423+
BOOST_AUTO_TEST_CASE(from_parts_2) {
426424
BOOST_CHECK_EQUAL(uri::uri("http://www.example.com/path?query#fragment"),
427425
uri::from_parts("http://www.example.com", "/path", "query", "fragment"));
428426
}
429427

430-
BOOST_AUTO_TEST_CASE(from_parts_3)
431-
{
428+
BOOST_AUTO_TEST_CASE(from_parts_3) {
432429
BOOST_CHECK_EQUAL(uri::uri("http://www.example.com/path?query"),
433430
uri::from_parts("http://www.example.com", "/path", "query"));
434431
}
435432

436-
BOOST_AUTO_TEST_CASE(from_parts_4)
437-
{
433+
BOOST_AUTO_TEST_CASE(from_parts_4) {
438434
BOOST_CHECK_EQUAL(uri::uri("http://www.example.com/path"),
439435
uri::from_parts("http://www.example.com", "/path"));
440436
}
441437

442-
BOOST_AUTO_TEST_CASE(from_file)
443-
{
438+
BOOST_AUTO_TEST_CASE(from_file) {
444439
boost::filesystem::path path("/a/path/to/a/file.txt");
445440
BOOST_CHECK_EQUAL(uri::uri("file:///a/path/to/a/file.txt"), uri::from_file(path));
446441
}
442+
443+
BOOST_AUTO_TEST_CASE(issue_104_test) {
444+
// https://github.com/cpp-netlib/cpp-netlib/issues/104
445+
boost::scoped_ptr<uri::uri> instance(new uri::uri("http://www.example.com/"));
446+
uri::uri copy = *instance;
447+
instance.reset();
448+
BOOST_CHECK_EQUAL(uri::scheme(copy), "http");
449+
}

0 commit comments

Comments
 (0)