1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:37:34 +00:00

LibWeb: Port ParsedCookie from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-11-22 08:36:23 +13:00 committed by Tim Flynn
parent f43313d099
commit 1b05598cd3
4 changed files with 21 additions and 20 deletions

View file

@ -12,6 +12,7 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibIPC/Decoder.h> #include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h> #include <LibIPC/Encoder.h>
#include <LibWeb/Infra/Strings.h>
#include <ctype.h> #include <ctype.h>
namespace Web::Cookie { namespace Web::Cookie {
@ -75,7 +76,7 @@ Optional<ParsedCookie> parse_cookie(StringView cookie_string)
return {}; return {};
// 6. The cookie-name is the name string, and the cookie-value is the value string. // 6. The cookie-name is the name string, and the cookie-value is the value string.
ParsedCookie parsed_cookie { name, value }; ParsedCookie parsed_cookie { MUST(String::from_utf8(name)), MUST(String::from_utf8(value)) };
parse_attributes(parsed_cookie, unparsed_attributes); parse_attributes(parsed_cookie, unparsed_attributes);
return parsed_cookie; return parsed_cookie;
@ -197,7 +198,7 @@ void on_domain_attribute(ParsedCookie& parsed_cookie, StringView attribute_value
} }
// Convert the cookie-domain to lower case. // Convert the cookie-domain to lower case.
parsed_cookie.domain = DeprecatedString(cookie_domain).to_lowercase(); parsed_cookie.domain = MUST(Infra::to_ascii_lowercase(cookie_domain));
} }
void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_value) void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_value)
@ -210,7 +211,7 @@ void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_value)
return; return;
// Let cookie-path be the attribute-value // Let cookie-path be the attribute-value
parsed_cookie.path = attribute_value; parsed_cookie.path = MUST(String::from_utf8(attribute_value));
} }
void on_secure_attribute(ParsedCookie& parsed_cookie) void on_secure_attribute(ParsedCookie& parsed_cookie)
@ -373,12 +374,12 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& coo
template<> template<>
ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder) ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
{ {
auto name = TRY(decoder.decode<DeprecatedString>()); auto name = TRY(decoder.decode<String>());
auto value = TRY(decoder.decode<DeprecatedString>()); auto value = TRY(decoder.decode<String>());
auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<UnixDateTime>>()); auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<UnixDateTime>>());
auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<UnixDateTime>>()); auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<UnixDateTime>>());
auto domain = TRY(decoder.decode<Optional<DeprecatedString>>()); auto domain = TRY(decoder.decode<Optional<String>>());
auto path = TRY(decoder.decode<Optional<DeprecatedString>>()); auto path = TRY(decoder.decode<Optional<String>>());
auto secure_attribute_present = TRY(decoder.decode<bool>()); auto secure_attribute_present = TRY(decoder.decode<bool>());
auto http_only_attribute_present = TRY(decoder.decode<bool>()); auto http_only_attribute_present = TRY(decoder.decode<bool>());
auto same_site_attribute = TRY(decoder.decode<Web::Cookie::SameSite>()); auto same_site_attribute = TRY(decoder.decode<Web::Cookie::SameSite>());

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/DeprecatedString.h>
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <LibIPC/Forward.h> #include <LibIPC/Forward.h>
#include <LibWeb/Cookie/Cookie.h> #include <LibWeb/Cookie/Cookie.h>
@ -15,13 +15,13 @@
namespace Web::Cookie { namespace Web::Cookie {
struct ParsedCookie { struct ParsedCookie {
DeprecatedString name; String name;
DeprecatedString value; String value;
SameSite same_site_attribute { SameSite::Default }; SameSite same_site_attribute { SameSite::Default };
Optional<UnixDateTime> expiry_time_from_expires_attribute {}; Optional<UnixDateTime> expiry_time_from_expires_attribute {};
Optional<UnixDateTime> expiry_time_from_max_age_attribute {}; Optional<UnixDateTime> expiry_time_from_max_age_attribute {};
Optional<DeprecatedString> domain {}; Optional<String> domain {};
Optional<DeprecatedString> path {}; Optional<String> path {};
bool secure_attribute_present { false }; bool secure_attribute_present { false };
bool http_only_attribute_present { false }; bool http_only_attribute_present { false };
}; };

View file

@ -290,7 +290,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
// https://tools.ietf.org/html/rfc6265#section-5.3 // https://tools.ietf.org/html/rfc6265#section-5.3
// 2. Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time to the current date and time. // 2. Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time to the current date and time.
Web::Cookie::Cookie cookie { MUST(String::from_deprecated_string(parsed_cookie.name)), MUST(String::from_deprecated_string(parsed_cookie.value)), parsed_cookie.same_site_attribute }; Web::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value, parsed_cookie.same_site_attribute };
cookie.creation_time = UnixDateTime::now(); cookie.creation_time = UnixDateTime::now();
cookie.last_access_time = cookie.creation_time; cookie.last_access_time = cookie.creation_time;
@ -313,7 +313,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
// 4. If the cookie-attribute-list contains an attribute with an attribute-name of "Domain": // 4. If the cookie-attribute-list contains an attribute with an attribute-name of "Domain":
if (parsed_cookie.domain.has_value()) { if (parsed_cookie.domain.has_value()) {
// Let the domain-attribute be the attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Domain". // Let the domain-attribute be the attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Domain".
cookie.domain = MUST(String::from_deprecated_string(parsed_cookie.domain.value())); cookie.domain = parsed_cookie.domain.value();
} }
// 5. If the user agent is configured to reject "public suffixes" and the domain-attribute is a public suffix: // 5. If the user agent is configured to reject "public suffixes" and the domain-attribute is a public suffix:
@ -347,7 +347,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
// 7. If the cookie-attribute-list contains an attribute with an attribute-name of "Path": // 7. If the cookie-attribute-list contains an attribute with an attribute-name of "Path":
if (parsed_cookie.path.has_value()) { if (parsed_cookie.path.has_value()) {
// Set the cookie's path to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Path". // Set the cookie's path to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Path".
cookie.path = MUST(String::from_deprecated_string(parsed_cookie.path.value())); cookie.path = parsed_cookie.path.value();
} else { } else {
cookie.path = MUST(String::from_deprecated_string(default_path(url))); cookie.path = MUST(String::from_deprecated_string(default_path(url)));
} }

View file

@ -1570,21 +1570,21 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso
// 7. Create a cookie in the cookie store associated with the active documents address using cookie name name, cookie value value, and an attribute-value list of the following cookie concepts listed in the table for cookie conversion from data: // 7. Create a cookie in the cookie store associated with the active documents address using cookie name name, cookie value value, and an attribute-value list of the following cookie concepts listed in the table for cookie conversion from data:
Web::Cookie::ParsedCookie cookie {}; Web::Cookie::ParsedCookie cookie {};
cookie.name = TRY(get_property(data, "name"sv)); cookie.name = MUST(String::from_deprecated_string(TRY(get_property(data, "name"sv))));
cookie.value = TRY(get_property(data, "value"sv)); cookie.value = MUST(String::from_deprecated_string(TRY(get_property(data, "value"sv))));
// Cookie path // Cookie path
// The value if the entry exists, otherwise "/". // The value if the entry exists, otherwise "/".
if (data.has("path"sv)) if (data.has("path"sv))
cookie.path = TRY(get_property(data, "path"sv)); cookie.path = MUST(String::from_deprecated_string(TRY(get_property(data, "path"sv))));
else else
cookie.path = "/"; cookie.path = "/"_string;
// Cookie domain // Cookie domain
// The value if the entry exists, otherwise the current browsing contexts active documents URL domain. // The value if the entry exists, otherwise the current browsing contexts active documents URL domain.
// NOTE: The otherwise case is handled by the CookieJar // NOTE: The otherwise case is handled by the CookieJar
if (data.has("domain"sv)) if (data.has("domain"sv))
cookie.domain = TRY(get_property(data, "domain"sv)); cookie.domain = MUST(String::from_deprecated_string(TRY(get_property(data, "domain"sv))));
// Cookie secure only // Cookie secure only
// The value if the entry exists, otherwise false. // The value if the entry exists, otherwise false.