Skip to content

Commit

Permalink
refactor(url_base): copy operation uses reference to underlying imple…
Browse files Browse the repository at this point in the history
…mentation

The copy operation from a url_view_base should use the pointed implementation rather than the underlying implementation so that url_views that refer to other urls are accounted for.

fix #872
  • Loading branch information
alandefreitas committed Oct 25, 2024
1 parent 41e6b07 commit d8cacb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/url_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ copy(url_view_base const& u)
}
reserve_impl(
u.size(), op);
impl_ = u.impl_;
impl_ = *u.pi_;
impl_.cs_ = s_;
impl_.from_ = {from::url};
std::memcpy(s_,
Expand Down
29 changes: 29 additions & 0 deletions test/unit/url_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ class url_view_test
BOOST_TEST_EQ(u1.data(), u2.data());
}

// issue #872
{
url base{"https://127.0.0.1"};
url_view ref = "/foo";

// url_view(url)
{
url_view base_view{base};
BOOST_TEST(base_view.has_scheme());
url dest;
auto res = resolve(base_view, ref, dest);
BOOST_TEST(res);
BOOST_TEST(dest.has_scheme());
BOOST_TEST_EQ(dest.buffer(), "https://127.0.0.1/foo");
}

// url_view::operator=(url)
{
url_view base_view;
base_view = base;
BOOST_TEST(base_view.has_scheme());
url dest;
auto res = resolve(base_view, ref, dest);
BOOST_TEST(res);
BOOST_TEST(dest.has_scheme());
BOOST_TEST_EQ(dest.buffer(), "https://127.0.0.1/foo");
}
}

// url_view(core::string_view)
{
BOOST_TEST_NO_THROW(url_view(
Expand Down

0 comments on commit d8cacb5

Please sign in to comment.