From c9a461ee75fa45d1d79ada7727383b2d67661efe Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 26 Apr 2024 15:06:48 -0400 Subject: [PATCH] LibWeb: Remove OOM propagation from Fetch::Infrastructure::HTTP --- Tests/LibWeb/TestFetchInfrastructure.cpp | 12 ++++++------ .../Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp | 6 +++--- .../Libraries/LibWeb/Fetch/Infrastructure/HTTP.h | 2 +- .../LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp | 2 +- Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/LibWeb/TestFetchInfrastructure.cpp b/Tests/LibWeb/TestFetchInfrastructure.cpp index 0ac6618733..06a28d7733 100644 --- a/Tests/LibWeb/TestFetchInfrastructure.cpp +++ b/Tests/LibWeb/TestFetchInfrastructure.cpp @@ -16,14 +16,14 @@ TEST_CASE(collect_an_http_quoted_string) auto test = "\"\""_string; GenericLexer lexer { test }; - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"\""_string); } { auto test = "\"abc\""_string; GenericLexer lexer { test }; - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"abc\""_string); } { @@ -32,7 +32,7 @@ TEST_CASE(collect_an_http_quoted_string) GenericLexer lexer { test }; lexer.ignore(4); - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"abc\""_string); } { @@ -41,7 +41,7 @@ TEST_CASE(collect_an_http_quoted_string) GenericLexer lexer { test }; lexer.ignore(4); - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"abc\""_string); } { @@ -50,14 +50,14 @@ TEST_CASE(collect_an_http_quoted_string) GenericLexer lexer { test }; lexer.ignore(4); - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"abc\""_string); } { auto test = "\"abc\" bar"_string; GenericLexer lexer { test }; - auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer)); + auto result = Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer); EXPECT_EQ(result, "\"abc\""_string); } } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp index 9e9ed333e2..ea4e64f8e5 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp @@ -12,7 +12,7 @@ namespace Web::Fetch::Infrastructure { // https://fetch.spec.whatwg.org/#collect-an-http-quoted-string -ErrorOr collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value) +String collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value) { // To collect an HTTP quoted string from a string input, given a position variable position and optionally an extract-value flag, run these steps: // 1. Let positionStart be position. @@ -69,10 +69,10 @@ ErrorOr collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStr // 6. If the extract-value flag is set, then return value. if (extract_value == HttpQuotedStringExtractValue::Yes) - return value.to_string(); + return MUST(value.to_string()); // 7. Return the code points from positionStart to position, inclusive, within input. - return String::from_utf8(lexer.input().substring_view(position_start, lexer.tell() - position_start)); + return MUST(String::from_utf8(lexer.input().substring_view(position_start, lexer.tell() - position_start))); } } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.h index eee29c4faf..d8574a8ad0 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.h @@ -37,6 +37,6 @@ enum class HttpQuotedStringExtractValue { Yes, }; -ErrorOr collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value = HttpQuotedStringExtractValue::No); +[[nodiscard]] String collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value = HttpQuotedStringExtractValue::No); } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp index f7f48fb56b..a8c427a33f 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp @@ -150,7 +150,7 @@ Optional> get_decode_and_split_header_value(ReadonlyBytes value) // 1. If the code point at position within input is U+0022 ("), then: if (lexer.peek() == '"') { // 1. Append the result of collecting an HTTP quoted string from input, given position, to temporaryValue. - temporary_value_builder.append(MUST(collect_an_http_quoted_string(lexer))); + temporary_value_builder.append(collect_an_http_quoted_string(lexer)); // 2. If position is not past the end of input, then continue. if (!lexer.is_eof()) diff --git a/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp b/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp index c56838e61e..0cfd663ad5 100644 --- a/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp +++ b/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp @@ -152,7 +152,7 @@ ErrorOr> MimeType::parse(StringView string) // 8. If the code point at position within input is U+0022 ("), then: if (lexer.peek() == '"') { // 1. Set parameterValue to the result of collecting an HTTP quoted string from input, given position and the extract-value flag. - parameter_value = TRY(Fetch::Infrastructure::collect_an_http_quoted_string(lexer, Fetch::Infrastructure::HttpQuotedStringExtractValue::Yes)); + parameter_value = Fetch::Infrastructure::collect_an_http_quoted_string(lexer, Fetch::Infrastructure::HttpQuotedStringExtractValue::Yes); // 2. Collect a sequence of code points that are not U+003B (;) from input, given position. lexer.ignore_until(';');