mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:27:35 +00:00
LibWeb: Port ParsedCookie from DeprecatedString to String
This commit is contained in:
parent
f43313d099
commit
1b05598cd3
4 changed files with 21 additions and 20 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace Web::Cookie {
|
||||
|
@ -75,7 +76,7 @@ Optional<ParsedCookie> parse_cookie(StringView cookie_string)
|
|||
return {};
|
||||
|
||||
// 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);
|
||||
return parsed_cookie;
|
||||
|
@ -197,7 +198,7 @@ void on_domain_attribute(ParsedCookie& parsed_cookie, StringView attribute_value
|
|||
}
|
||||
|
||||
// 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)
|
||||
|
@ -210,7 +211,7 @@ void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_value)
|
|||
return;
|
||||
|
||||
// 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)
|
||||
|
@ -373,12 +374,12 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& coo
|
|||
template<>
|
||||
ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
|
||||
{
|
||||
auto name = TRY(decoder.decode<DeprecatedString>());
|
||||
auto value = TRY(decoder.decode<DeprecatedString>());
|
||||
auto name = TRY(decoder.decode<String>());
|
||||
auto value = TRY(decoder.decode<String>());
|
||||
auto expiry_time_from_expires_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 path = TRY(decoder.decode<Optional<DeprecatedString>>());
|
||||
auto domain = TRY(decoder.decode<Optional<String>>());
|
||||
auto path = TRY(decoder.decode<Optional<String>>());
|
||||
auto secure_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>());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Time.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
|
@ -15,13 +15,13 @@
|
|||
namespace Web::Cookie {
|
||||
|
||||
struct ParsedCookie {
|
||||
DeprecatedString name;
|
||||
DeprecatedString value;
|
||||
String name;
|
||||
String value;
|
||||
SameSite same_site_attribute { SameSite::Default };
|
||||
Optional<UnixDateTime> expiry_time_from_expires_attribute {};
|
||||
Optional<UnixDateTime> expiry_time_from_max_age_attribute {};
|
||||
Optional<DeprecatedString> domain {};
|
||||
Optional<DeprecatedString> path {};
|
||||
Optional<String> domain {};
|
||||
Optional<String> path {};
|
||||
bool secure_attribute_present { false };
|
||||
bool http_only_attribute_present { false };
|
||||
};
|
||||
|
|
|
@ -290,7 +290,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
|
|||
// 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.
|
||||
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.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":
|
||||
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".
|
||||
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:
|
||||
|
@ -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":
|
||||
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".
|
||||
cookie.path = MUST(String::from_deprecated_string(parsed_cookie.path.value()));
|
||||
cookie.path = parsed_cookie.path.value();
|
||||
} else {
|
||||
cookie.path = MUST(String::from_deprecated_string(default_path(url)));
|
||||
}
|
||||
|
|
|
@ -1570,21 +1570,21 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso
|
|||
|
||||
// 7. Create a cookie in the cookie store associated with the active document’s 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 {};
|
||||
cookie.name = TRY(get_property(data, "name"sv));
|
||||
cookie.value = TRY(get_property(data, "value"sv));
|
||||
cookie.name = MUST(String::from_deprecated_string(TRY(get_property(data, "name"sv))));
|
||||
cookie.value = MUST(String::from_deprecated_string(TRY(get_property(data, "value"sv))));
|
||||
|
||||
// Cookie path
|
||||
// The value if the entry exists, otherwise "/".
|
||||
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
|
||||
cookie.path = "/";
|
||||
cookie.path = "/"_string;
|
||||
|
||||
// Cookie domain
|
||||
// The value if the entry exists, otherwise the current browsing context’s active document’s URL domain.
|
||||
// NOTE: The otherwise case is handled by the CookieJar
|
||||
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
|
||||
// The value if the entry exists, otherwise false.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue