Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions include/boost/url/impl/url_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,11 @@ normalize_path()
// remove_dot_segments can produce output that
// needs a 2-byte shield prefix, as explained
// in step 2. The memmove below writes within
// the original path region (before shrink_impl)
// and always has room because ".." cancellation
// consumes >= 5 bytes but we only need 2 for the
// shield.
// the path region; when ".." cancellation has
// consumed >= 2 bytes there is already slack,
// but for short inputs that take the shield
// branch without any cancellation (e.g. "//"),
// the region has to grow to fit the prefix.
//
bool needs_shield = [&]()
{
Expand Down Expand Up @@ -2204,7 +2205,14 @@ normalize_path()
}();
if (needs_shield)
{
BOOST_ASSERT(n + 2 <= pn);
if (n + 2 > pn)
{
// No ".. cancellation slack — grow the path
// region to fit the 2-byte shield. p_dest may
// be invalidated by the underlying reallocation.
p_dest = resize_impl(id_path, n + 2, op);
pn = n + 2;
}
std::memmove(p_dest + 2, p_dest, n);
if (was_absolute)
{
Expand Down
15 changes: 15 additions & 0 deletions test/unit/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,21 @@ struct url_test
check("", "");
}

// normalize path without authority: a "//" path must
// grow the buffer before prepending the "/." shield.
// https://github.com/boostorg/url/issues/992
{
auto check = [](core::string_view p,
core::string_view e) {
url u = parse_origin_form(p).value();
u.normalize();
BOOST_TEST_EQ(u.encoded_path(), e);
};
check("//", "/.//");
check("///", "/.///");
check("////", "/.////");
}

// inequality
{
auto check = [](core::string_view e1,
Expand Down
Loading