Commit graph

17 commits

Author SHA1 Message Date
Shannon Booth
5bed8f4055 LibURL+LibWeb: Make URL::basic_parse return an Optional<URL>
URL::basic_parse has a subtle bug where the resulting URL is not set
to valid when StateOveride is provided and the URL parser early returns
a valid URL.

This has not surfaced as a problem so far, as the only users of the
state override API provide an already valid URL buffer and also ignore
the result of basic parsing with a state override.

However, this bug surfaces implementing the URL pattern spec, which as
part of URL canonicalization:
 * Provides a dummy URL record
 * Basic URL parses that URL with state override
 * Checks the result of the URL parser to validate the URL

While we could set URL validity on every early return of the URL parser
during state override, it has been a long standing FIXME around the code
to try and remove the awkward validity state of the URL class. So this
commit makes the first stage of this change by migrating the basic
parser API to return Optional, which also happens to make this subtle
issue not a problem any more.
2025-01-11 10:08:29 -05:00
Shannon Booth
87c8ae31d3 LibURL: Set IDNA's IgnoreInvalidPunycode to false
See: https://github.com/whatwg/url/commit/a6e449 - which should have no
functional change.
2024-12-05 17:29:49 +01:00
Shannon Booth
5dfb825c5c LibURL: Set IDNA's CheckHyphens to the value of beStrict
See: https://github.com/whatwg/url/commit/cd8f1d
2024-12-05 17:29:49 +01:00
Shannon Booth
24267db6b2 LibURL: Implement "find the IPv6 address compressed piece index" helper
This was an editorial change in the spec to put a somewhat complex spec
step in it's own AO.
2024-12-05 17:29:49 +01:00
Shannon Booth
0b4670fb7c LibURL: Percent decode over byte sequence
Instead of going over UTF-8 code points. This better follows the spec,
and is also more performant.
2024-12-05 17:29:49 +01:00
Shannon Booth
0fa54c2327 LibURL+LibWeb: Make URL::serialize return a String
Simplifying a bunch of uneeded error handling around the place.
2024-12-04 16:34:13 +00:00
Jonne Ransijn
d7596a0a61 AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.

NOTE: We make an exception for trivially copyable types, since they
are, well, trivially copyable.

Co-authored-by: kleines Filmröllchen <filmroellchen@serenityos.org>
2024-12-04 01:58:22 +01:00
Sam Atkins
900c131178 LibURL: Make URL::serialized_host() infallible
This can no longer fail, so update the return type to match.

This makes a few more methods now unable to return errors, but one thing
at a time. 😅
2024-11-30 12:07:39 +01:00
Sam Atkins
b83f015c70 LibURL: Implement Site concept 2024-11-30 12:07:39 +01:00
Sam Atkins
2e64e0b836 LibURL: Migrate Origin scheme from ByteString to String 2024-11-30 12:07:39 +01:00
Sam Atkins
7f7f6e490b LibURL: Implement Host::public_suffix() and registrable_domain()
These algorithms are used in following commits.
2024-11-30 12:07:39 +01:00
Sam Atkins
63688148b9 LibURL: Promote Host to a proper class
This lets us move a few Host-related functions (like serialization and
checks for what the Host is) into Host instead of having them dotted
around the codebase.

For now, the interface is still very Variant-like, to avoid having to
change quite so much in one go.
2024-11-30 12:07:39 +01:00
Sam Atkins
90e763de4c LibURL: Replace Host's Empty state with making Url's Host optional
A couple of reasons:
- Origin's Host (when in the tuple state) can't be null
- There's an "empty host" concept in the spec which is NOT the same as a
  null Host, and that was confusing me.
2024-11-30 12:07:39 +01:00
Sam Atkins
8b984c0c57 LibURL: Clarify whether an Origin is opaque
Origins are immutable and we know on construction whether an Origin is
opaque. This also removes an implicit reliance on Host's Empty state.
2024-11-30 12:07:39 +01:00
Sam Atkins
3124dca528 LibURL+LibWebView: Move public suffix data to LibURL 2024-11-30 12:07:39 +01:00
Shannon Booth
8f6fe1de83 LibURL+LibWeb: Make URL serialization return a String
This can only ever fail from OOM, and will never by string containing
random byte sequences.
2024-11-23 16:43:55 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00