]> granicus.if.org Git - icinga2/commitdiff
Fix path interpretion in URL parser
authorJean-Marcel Flach <jean-marcel.flach@netways.de>
Wed, 8 Jul 2015 11:08:02 +0000 (13:08 +0200)
committerJean-Marcel Flach <jean-marcel.flach@netways.de>
Wed, 8 Jul 2015 11:14:05 +0000 (13:14 +0200)
The URL parser incorrectly used to interpret the path
"/" as a path "/" instead of as empty.
Test cases were added.

refs #9470

lib/base/url.cpp
test/base-url.cpp

index d88ab7844b8f6ae12ad9c7da2dbdeb116bec73f8..c456d36dee7d03d39e09c9a5b8d3525a0368f641 100644 (file)
@@ -48,7 +48,6 @@ Url::Url(const String& base_url)
                BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: '/' expected after scheme."));
 
        if (url.GetLength() == 1) {
-               m_Path.push_back("/");
                return;
        }
 
index 50f239c157720853094554ac7d4ced14dd919069..28d82296779830dfe4a7259c7a703e979addaaed 100644 (file)
@@ -64,6 +64,9 @@ BOOST_AUTO_TEST_CASE(format)
 
        url = new Url("/foo/bar/index.php?blaka");
        BOOST_CHECK(new Url(url->Format()));
+
+       url = new Url("/");
+       BOOST_CHECK(url->Format() == "/");
 }
 
 BOOST_AUTO_TEST_CASE(illegal_legal_strings)
@@ -72,6 +75,7 @@ BOOST_AUTO_TEST_CASE(illegal_legal_strings)
        BOOST_CHECK_THROW(new Url("/?]=gar"), std::invalid_argument);
        BOOST_CHECK(new Url("/?foo=baz??&\?\?=/?")); //Valid
        BOOST_CHECK_THROW(new Url("/?foo=bar&foo=ba"), std::invalid_argument);
+       BOOST_CHECK(new Url("/"));
        BOOST_CHECK_THROW(new Url("/?foo=bar&[]=d"), std::invalid_argument);
        BOOST_CHECK_THROW(new Url("/?fo=&bar=garOA"), std::invalid_argument);
 }