diff --git a/include/boost/url/impl/params_encoded_view.ipp b/include/boost/url/impl/params_encoded_view.ipp index 0470a472..b0a27a90 100644 --- a/include/boost/url/impl/params_encoded_view.ipp +++ b/include/boost/url/impl/params_encoded_view.ipp @@ -192,7 +192,9 @@ params_encoded_view:: begin() const noexcept -> iterator { - return { s_ }; + if(n_ > 0) + return { s_ }; + return { s_, 0 }; } auto diff --git a/include/boost/url/impl/params_view.ipp b/include/boost/url/impl/params_view.ipp index e9237a4b..26f738f7 100644 --- a/include/boost/url/impl/params_view.ipp +++ b/include/boost/url/impl/params_view.ipp @@ -247,7 +247,9 @@ params_view:: begin() const noexcept -> iterator { - return { s_, a_ }; + if(n_ > 0) + return { s_, a_ }; + return { s_, 0, a_ }; } auto diff --git a/test/limits/CMakeLists.txt b/test/limits/CMakeLists.txt index 1719c05f..0a08ced4 100644 --- a/test/limits/CMakeLists.txt +++ b/test/limits/CMakeLists.txt @@ -30,4 +30,3 @@ target_link_libraries(boost_url_limits PRIVATE target_link_libraries(boost_url_limits INTERFACE Boost::url) add_test(NAME boost_url_limits COMMAND boost_url_limits) add_dependencies(tests boost_url_limits) - diff --git a/test/unit/params.cpp b/test/unit/params.cpp index 8ffefea2..22b47c38 100644 --- a/test/unit/params.cpp +++ b/test/unit/params.cpp @@ -496,6 +496,20 @@ class params_test BOOST_TEST(it2 >= it); } + void + testRange() + { + // issue 129 + // empty range iterates once + { + url u = parse_uri( + "http://example.com/index.htm").value(); + auto const r = u.params(); + BOOST_TEST( + r.begin() == r.end()); + } + } + void run() { @@ -505,6 +519,7 @@ class params_test testModifiers(); testLookup(); testIterators(); + testRange(); } }; diff --git a/test/unit/params_encoded.cpp b/test/unit/params_encoded.cpp index 6c8f1c54..60302eec 100644 --- a/test/unit/params_encoded.cpp +++ b/test/unit/params_encoded.cpp @@ -506,6 +506,20 @@ class params_encoded_test } } + void + testRange() + { + // issue 129 + // empty range iterates once + { + url u = parse_uri( + "http://example.com/index.htm").value(); + auto const r = u.encoded_params(); + BOOST_TEST( + r.begin() == r.end()); + } + } + void run() { @@ -515,6 +529,7 @@ class params_encoded_test testModifiers(); testLookup(); testIterators(); + testRange(); } }; diff --git a/test/unit/params_encoded_view.cpp b/test/unit/params_encoded_view.cpp index 5840b598..fbfbe4b7 100644 --- a/test/unit/params_encoded_view.cpp +++ b/test/unit/params_encoded_view.cpp @@ -173,6 +173,20 @@ class params_encoded_view_test } } + void + testRange() + { + // issue 129 + // empty range iterates once + { + url_view u = parse_uri( + "http://example.com/index.htm").value(); + auto const r = u.encoded_params(); + BOOST_TEST( + r.begin() == r.end()); + } + } + void run() { @@ -181,6 +195,7 @@ class params_encoded_view_test testLookup(); testIterators(); testEncoding(); + testRange(); } }; diff --git a/test/unit/params_view.cpp b/test/unit/params_view.cpp index 1bab880f..45f67dc7 100644 --- a/test/unit/params_view.cpp +++ b/test/unit/params_view.cpp @@ -164,6 +164,20 @@ class params_view_test } } + void + testRange() + { + // issue 129 + // empty range iterates once + { + url_view u = parse_uri( + "http://example.com/index.htm").value(); + auto const r = u.params(); + BOOST_TEST( + r.begin() == r.end()); + } + } + void run() { @@ -172,6 +186,7 @@ class params_view_test testLookup(); testIterators(); testEncoding(); + testRange(); } };