mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Make sure URL retains trailing slash if present in complete_url
This commit is contained in:
parent
013cb76d77
commit
b5b08fba92
Notes:
sideshowbarker
2024-07-19 06:33:35 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/b5b08fba927 Pull-request: https://github.com/SerenityOS/serenity/pull/2261 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/bugaevc
2 changed files with 17 additions and 1 deletions
|
@ -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)
|
||||
|
|
10
AK/URL.cpp
10
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue