From b5b08fba9277f0c71e0561e89d36e9151cbe91d0 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Sun, 17 May 2020 21:41:36 +1000 Subject: [PATCH] AK: Make sure URL retains trailing slash if present in complete_url --- AK/Tests/TestURL.cpp | 8 ++++++++ AK/URL.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/AK/Tests/TestURL.cpp b/AK/Tests/TestURL.cpp index 380c15ccfdc..07467bf27f5 100644 --- a/AK/Tests/TestURL.cpp +++ b/AK/Tests/TestURL.cpp @@ -157,4 +157,12 @@ TEST_CASE(about_url) EXPECT_EQ(url.to_string(), "about:blank"); } +TEST_CASE(trailing_slash_with_complete_url) +{ + EXPECT_EQ(URL("http://a/b/").complete_url("c/").to_string(), "http://a/b/c/"); + EXPECT_EQ(URL("http://a/b/").complete_url("c").to_string(), "http://a/b/c"); + EXPECT_EQ(URL("http://a/b").complete_url("c/").to_string(), "http://a/c/"); + EXPECT_EQ(URL("http://a/b").complete_url("c").to_string(), "http://a/c"); +} + TEST_MAIN(URL) diff --git a/AK/URL.cpp b/AK/URL.cpp index 6263a38ac9b..d8acf57c36e 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -323,8 +323,16 @@ URL URL::complete_url(const String& string) const auto built = builder.to_string(); fspath = FileSystemPath(built); + built = fspath.string(); + if (string.ends_with('/') && !built.ends_with('/')) { + builder.clear(); + builder.append(built); + builder.append('/'); + built = builder.to_string(); + } + url = *this; - url.set_path(fspath.string()); + url.set_path(built); return url; }