From 12351d9b86270a951d33dd3863c9cb0811fc01a9 Mon Sep 17 00:00:00 2001 From: Kalpesh Pandya Date: Thu, 14 Oct 2021 01:29:06 +0530 Subject: [PATCH] src/rgw: Fix for malformed url This PR solves: https://tracker.ceph.com/issues/52738 It is solved by making changes to rgw_url.cc A test is also added to check it's working. Signed-off-by: Kalpesh Pandya (cherry picked from commit 2916f2439eb2f62bc08c3e283b13391302b3e497) --- src/rgw/rgw_url.cc | 2 +- src/test/rgw/test_rgw_url.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_url.cc b/src/rgw/rgw_url.cc index 58f7b5490538c..7fd4788d77c6d 100644 --- a/src/rgw/rgw_url.cc +++ b/src/rgw/rgw_url.cc @@ -14,7 +14,7 @@ namespace { const std::string schema_re = "([[:alpha:]]+:\\/\\/)"; const std::string user_pass_re = "(([^:\\s]+):([^@\\s]+)@)?"; const std::string host_port_re = "([[:alnum:].:-]+)"; - const std::string path_re = "(/[[:print:]]+)?"; + const std::string path_re = "(/[[:print:]]*)?"; } bool parse_url_authority(const std::string& url, std::string& host, std::string& user, std::string& password) { diff --git a/src/test/rgw/test_rgw_url.cc b/src/test/rgw/test_rgw_url.cc index d38457b815d2e..b61e1d5959210 100644 --- a/src/test/rgw/test_rgw_url.cc +++ b/src/test/rgw/test_rgw_url.cc @@ -19,6 +19,18 @@ TEST(TestURL, SimpleAuthority) EXPECT_STREQ(host.c_str(), "example.com"); } +TEST(TestURL, SimpleAuthority_1) +{ + std::string host; + std::string user; + std::string password; + const std::string url = "http://example.com/"; + ASSERT_TRUE(parse_url_authority(url, host, user, password)); + ASSERT_TRUE(user.empty()); + ASSERT_TRUE(password.empty()); + EXPECT_STREQ(host.c_str(), "example.com"); +} + TEST(TestURL, IPAuthority) { std::string host; -- 2.39.5