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
6 changes: 3 additions & 3 deletions include/boost/url/decode_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class decode_view

@par Preconditions
@code
not this->empty()
n <= this->size()
@endcode

@par Complexity
Expand All @@ -477,13 +477,13 @@ class decode_view
@par Example
@code
decode_view d( "Program%20Files" );
d.remove_prefix( 6 );
d.remove_suffix( 6 );
assert( d == "Program" );
@endcode

@par Preconditions
@code
not this->empty()
n <= this->size()
@endcode

@par Complexity
Expand Down
4 changes: 2 additions & 2 deletions include/boost/url/detail/impl/params_iter_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ decrement() noexcept
{
// value
nv = p1 - p; // with '='
dv += dk;
dk = 0;
dv += dk - 1;
dk = 1;
}
else if(*p == '%')
{
Expand Down
2 changes: 2 additions & 0 deletions src/decode_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void
decode_view::
remove_prefix( size_type n )
{
BOOST_ASSERT(n <= dn_);
auto it = begin();
auto n0 = n;
while (n)
Expand All @@ -68,6 +69,7 @@ void
decode_view::
remove_suffix( size_type n )
{
BOOST_ASSERT(n <= dn_);
auto it = end();
auto n0 = n;
while (n)
Expand Down
103 changes: 103 additions & 0 deletions test/unit/decode_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,42 @@ struct decode_view_test
BOOST_TEST_EQ(s, "uri test");
}

// remove_prefix() with n == size() (issue #973)
{
decode_view s(str, no_plus_opt);
s.remove_prefix(s.size());
BOOST_TEST(s.empty());
BOOST_TEST_EQ(s.size(), 0u);
}

// remove_prefix() with n == 0
{
decode_view s(str, no_plus_opt);
s.remove_prefix(0);
BOOST_TEST_EQ(s, "a uri test");
}

// remove_suffix()
{
decode_view s(str);
s.remove_suffix(5);
BOOST_TEST_EQ(s, "a uri");
}

// remove_suffix() with n == size() (issue #973)
{
decode_view s(str, no_plus_opt);
s.remove_suffix(s.size());
BOOST_TEST(s.empty());
BOOST_TEST_EQ(s.size(), 0u);
}

// remove_suffix() with n == 0
{
decode_view s(str, no_plus_opt);
s.remove_suffix(0);
BOOST_TEST_EQ(s, "a uri test");
}
}

void
Expand Down Expand Up @@ -372,6 +402,78 @@ struct decode_view_test
#endif
}

void
testJavadocs()
{
// decode_view()
{
decode_view ds;

boost::ignore_unused(ds);
}

// decode_view(pct_string_view, encoding_opts)
{
decode_view ds( "Program%20Files" );

boost::ignore_unused(ds);
}

// empty()
{
BOOST_TEST( decode_view( "" ).empty() );
}

// size()
{
BOOST_TEST_EQ( decode_view( "Program%20Files" ).size(), 13u );
}

// front()
{
BOOST_TEST_EQ( decode_view( "Program%20Files" ).front(), 'P' );
}

// back()
{
BOOST_TEST_EQ( decode_view( "Program%20Files" ).back(), 's' );
}

// starts_with(core::string_view)
{
BOOST_TEST( decode_view( "Program%20Files" ).starts_with("Program") );
}

// ends_with(core::string_view)
{
BOOST_TEST( decode_view( "Program%20Files" ).ends_with("Files") );
}

// starts_with(char)
{
BOOST_TEST( decode_view( "Program%20Files" ).starts_with('P') );
}

// ends_with(char)
{
BOOST_TEST( decode_view( "Program%20Files" ).ends_with('s') );
}

// remove_prefix(size_type)
{
decode_view d( "Program%20Files" );
d.remove_prefix( 8 );
BOOST_TEST_EQ( d, "Files" );
}

// remove_suffix(size_type)
{
decode_view d( "Program%20Files" );
d.remove_suffix( 6 );
BOOST_TEST_EQ( d, "Program" );
}
}

void
run()
{
Expand All @@ -385,6 +487,7 @@ struct decode_view_test
testStream();
testPR127Cases();
testBorrowedRange();
testJavadocs();
}
};

Expand Down
7 changes: 7 additions & 0 deletions test/unit/params_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ struct params_base_test
check( "?first=John&last=Doe", { { "first", "John" }, { "last", "Doe" } } );
check( "?key=value&", { { "key", "value" }, {} } );
check( "?&key=value", { {}, { "key", "value" } } );
check( "?a=b=c", { { "a", "b=c" } } );
check( "?k=v=w&x=y", { { "k", "v=w" }, { "x", "y" } } );
check( "?x=y&k=v=w", { { "x", "y" }, { "k", "v=w" } } );
check( "?a=b=c=d", { { "a", "b=c=d" } } );
check( "?===", { { "", "==" } } );
check( "?a==b", { { "a", "=b" } } );
check( "?a=1&b=2=3&c=4", { { "a", "1" }, { "b", "2=3" }, { "c", "4" } } );
}

void
Expand Down
7 changes: 7 additions & 0 deletions test/unit/params_encoded_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ struct params_encoded_base_test
check( "?first=John&last=Doe", { { "first", "John" }, { "last", "Doe" } } );
check( "?key=value&", { { "key", "value" }, {} } );
check( "?&key=value", { {}, { "key", "value" } } );
check( "?a=b=c", { { "a", "b=c" } } );
check( "?k=v=w&x=y", { { "k", "v=w" }, { "x", "y" } } );
check( "?x=y&k=v=w", { { "x", "y" }, { "k", "v=w" } } );
check( "?a=b=c=d", { { "a", "b=c=d" } } );
check( "?===", { { "", "==" } } );
check( "?a==b", { { "a", "=b" } } );
check( "?a=1&b=2=3&c=4", { { "a", "1" }, { "b", "2=3" }, { "c", "4" } } );
}

void
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 @@ -925,6 +925,35 @@ class url_view_test
{
BOOST_TEST_NO_THROW(url_view(
"javascript:alert(1)"));

// issue #926
{
url_view u(
"rtmp://push-rtmp-hs-f5.douyincdn.com"
"/thirdgame"
"?stream-117965406598857482"
"?arch_hrchy=w1"
"&exp_hrchy=w1"
"&expire=1758426355"
"&sign=7dbc2a8011a0faf01a5a22420b981d0c");
BOOST_TEST(u.has_scheme());
BOOST_TEST_EQ(u.scheme(), "rtmp");
BOOST_TEST(u.has_authority());
BOOST_TEST_EQ(u.host(), "push-rtmp-hs-f5.douyincdn.com");
BOOST_TEST_EQ(u.path(), "/thirdgame");
BOOST_TEST_EQ(u.encoded_path(), "/thirdgame");
auto segs = u.encoded_segments();
BOOST_TEST_EQ(segs.size(), 1u);
BOOST_TEST_EQ(*segs.begin(), "thirdgame");
BOOST_TEST(u.has_query());
BOOST_TEST_EQ(u.encoded_query(),
"stream-117965406598857482"
"?arch_hrchy=w1"
"&exp_hrchy=w1"
"&expire=1758426355"
"&sign=7dbc2a8011a0faf01a5a22420b981d0c");
BOOST_TEST(! u.has_fragment());
}
}

void
Expand Down
Loading