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
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- [[#5130]](https://github.com/Azure/azure-sdk-for-cpp/issues/5130) `Url::AppendPath()` and `Url::SetPath()` may end up with a double slash at the beginning of a path.

### Other Changes

## 1.11.0-beta.2 (2023-11-02)
Expand Down
5 changes: 4 additions & 1 deletion sdk/core/azure-core/src/http/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ std::string Url::GetUrlWithoutQuery(bool relative) const
{
if (!relative)
{
url += "/";
if (m_encodedPath.empty() || m_encodedPath[0] != '/')
{
url += "/";
}
}

url += m_encodedPath;
Expand Down
45 changes: 45 additions & 0 deletions sdk/core/azure-core/test/ut/url_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,49 @@ namespace Azure { namespace Core { namespace Test {
EXPECT_NE(params.find("param"), params.end());
EXPECT_EQ(params["param"], "value");
}

TEST(URL, LeadingSlashInPath)
{
Core::Url const u0("https://www.microsoft.com");
Core::Url const u1("https://www.microsoft.com/");

EXPECT_EQ(u0.GetAbsoluteUrl(), "https://www.microsoft.com");
EXPECT_EQ(u1.GetAbsoluteUrl(), "https://www.microsoft.com");

{
auto url0 = u0;
auto url1 = u1;
url0.AppendPath("path");
url1.AppendPath("path");
EXPECT_EQ(url0.GetAbsoluteUrl(), "https://www.microsoft.com/path");
EXPECT_EQ(url1.GetAbsoluteUrl(), "https://www.microsoft.com/path");
}

{
auto url0 = u0;
auto url1 = u1;
url0.AppendPath("/path");
url1.AppendPath("/path");
EXPECT_EQ(url0.GetAbsoluteUrl(), "https://www.microsoft.com/path");
EXPECT_EQ(url1.GetAbsoluteUrl(), "https://www.microsoft.com/path");
}

{
auto url0 = u0;
auto url1 = u1;
url0.SetPath("path");
url1.SetPath("path");
EXPECT_EQ(url0.GetAbsoluteUrl(), "https://www.microsoft.com/path");
EXPECT_EQ(url1.GetAbsoluteUrl(), "https://www.microsoft.com/path");
}

{
auto url0 = u0;
auto url1 = u1;
url0.SetPath("/path");
url1.SetPath("/path");
EXPECT_EQ(url0.GetAbsoluteUrl(), "https://www.microsoft.com/path");
EXPECT_EQ(url1.GetAbsoluteUrl(), "https://www.microsoft.com/path");
}
}
}}} // namespace Azure::Core::Test