mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Strip leading/trailing C0-control-or-space in URLs correctly
We have to stop scanning once we hit a non-strippable character. Add some tests to cover this.
This commit is contained in:
parent
468bb54677
commit
c0d1a75881
Notes:
sideshowbarker
2024-07-18 17:03:05 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c0d1a758815
2 changed files with 27 additions and 2 deletions
|
@ -196,12 +196,16 @@ URL URLParser::parse(Badge<URL>, const StringView& raw_input, URL const* base_ur
|
|||
if (raw_input[i] <= 0x20) {
|
||||
++start_index;
|
||||
has_validation_error = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < raw_input.length(); ++i) {
|
||||
if (raw_input[raw_input.length() - 1 - i] <= 0x20) {
|
||||
for (ssize_t i = raw_input.length() - 1; i >= 0; --i) {
|
||||
if (raw_input[i] <= 0x20) {
|
||||
--end_index;
|
||||
has_validation_error = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has_validation_error)
|
||||
|
|
|
@ -307,3 +307,24 @@ TEST_CASE(complete_url)
|
|||
|
||||
EXPECT(base_url.complete_url("../index.html#fragment").equals(base_url));
|
||||
}
|
||||
|
||||
TEST_CASE(leading_whitespace)
|
||||
{
|
||||
URL url { " https://foo.com/" };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
||||
TEST_CASE(trailing_whitespace)
|
||||
{
|
||||
URL url { "https://foo.com/ " };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
||||
TEST_CASE(leading_and_trailing_whitespace)
|
||||
{
|
||||
URL url { " https://foo.com/ " };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue