Commit graph

130 commits

Author SHA1 Message Date
Shannon Booth
250842d36a LibURL: Use encoding_rs for form URL encoding
Replace the Rust URL form-encoding callback bridge into C++ TextCodec
with a direct encoding_rs encoder.

This keeps percent-encode-after-encoding entirely in Rust and removes
liburl_rust's dependency on LibTextCodec.

It also happens to fix ISO-2022-JP URL encoding of literal U+FFFD.

The LibTextCodec reverse lookup treats generated 0xFFFD table holes as
real JIS0208 mappings, so literal U+FFFD skipped the encoder-error
path. encoding_rs treats U+FFFD as unmappable, so URL encoding emits
the required numeric character reference.
2026-06-20 21:56:43 +02:00
Shannon Booth
3f7b31fc78 LibURL: Let Host use PublicSuffixData star rule matching
Ever since PublicSuffixData was created, it was using "no star rule"
matching, which is what is needed for the address bar to distinguish
between a domain and a search. URL::Host on the other hand requires
the fallback star rule. Which rule is needed depends on the use case
of the PSL. Support both use cases by a flag in PublicSuffixData.
2026-06-16 06:14:07 +02:00
Shannon Booth
fc740068d2 LibURL/Pattern: Avoid eliding default ports in port patterns 2026-06-15 13:45:37 +02:00
Timothy Flynn
496c88d0c9 LibWebView: Add about:history to view, query and mangage browser history
This adds a WebUI to view the local browsing history, with controls to
search and delete entries. The APIs used to search history are paginated
to prevent excessive query sizes.
2026-06-10 20:27:36 +02:00
Timothy Flynn
409e5edbf1 LibURL+LibWeb+LibWebView: Move internal URLs to their own header
This nearly eliminates the compilation impact of adding a new WebUI URL.
2026-06-10 20:27:36 +02:00
Shannon Booth
5ef34ecb7a LibURL: Use libpsl for public suffix matching
Replace the generated public suffix table and custom matcher with a
direct LibURL PublicSuffixData implementation backed by libpsl. This
drops our PSL download/generator path and uses the same library already
used by libcurl.

Performance is comparable before and after, while LibURL binary size
is smaller.
2026-06-10 11:43:44 +02:00
Shannon Booth
20bfc49083 LibURL: Preserve trailing dots in public suffix matching
PublicSuffixData handled trailing-dot hosts incorrectly when a PSL rule
matched, causing returned public suffix and registrable-domain results
to drop the trailing dot.

Make PublicSuffixData skip leading dots for matching, ignore a single
trailing dot while running the PSL algorithm, and append that trailing
dot back to returned results.
2026-06-08 20:19:06 +02:00
Shannon Booth
9b80ac00be LibURL: Move registrable-domain PSL lookup to PublicSuffixData
Move the registrable-domain helper from URL into PublicSuffixData and
name it find_matching_registrable_domain().

This keeps it alongside find_matching_public_suffix(), making it clear
that both APIs only return results matched from the PSL data, while
Host::public_suffix() implements the URL Standard fallback to the
top-level domain.
2026-06-08 20:19:06 +02:00
Shannon Booth
ac344a5196 LibURL: Clarify PSL matching API names
Rename PublicSuffixData's raw lookup helpers to make it clear that they
only return public suffixes matched from the PSL data.

This distinguishes them from Host::public_suffix(), which implements the
URL Standard definition and falls back to the top-level domain when no
PSL rule matches.

We need both layers because address bar handling needs the raw lookup to
decide whether input should be treated as a URL or as a search.
2026-06-08 20:19:06 +02:00
Tim Ledbetter
3771bd5d4a LibURL: Advance past the '@' delimiter after batch-parsing userinfo
After batch-processing the userinfo, the authority state advanced the
parse pointer onto the '@' and relied on the end-of-loop increment to
step past it. That increment uses the byte length of the authority's
first code point, not the delimiter's. When the first code point was
multi-byte, the pointer overshot into the middle of a code point and
the next iteration sliced the string at a non-char boundary causing the
process to panic. We now step past the delimiter explicitly so we don't
need to rely on the end of loop increment to do so.
2026-06-07 11:29:43 +01:00
Shannon Booth
8c19e4b5ce LibURL: Prefer Types.h typedefs over inttypes.h 2026-05-30 01:41:34 +02:00
Shannon Booth
b4f46211d2 LibURL: Replace WTF-8 surrogates before Rust URL parsing
The Rust URL FFI used String::from_utf8_lossy() on raw bytes from C++.
That was not equivalent to the old C++ parser behavior for WTF-8 encoded
surrogates. For example a byte sequence such as ED A0 80 was treated as
three invalid UTF-8 bytes, producing three U+FFFD replacement
characters.

Instead use String::from_utf8_with_replacement_character and let Rust
borrow the input as &str.
2026-05-30 01:41:34 +02:00
Shannon Booth
4a986de52f LibURL: Optimize ASCII path/query parsing
Copy contiguous ASCII path/query runs in one slice append, instead of
processing each code point individually. Fall back to the normal state
machine for delimiters, percent escapes, non-ASCII input, and validation
cases.

This gives a 2.4x speedup on a benchmark parsing common web URLs.
2026-05-28 09:27:41 +02:00
Shannon Booth
331dd40d9c LibURL: Remove C++ URL Parser implementation
Only exposing compatability wrappers and percent_encode_after_encoding.
2026-05-28 09:27:41 +02:00
Shannon Booth
57cc7b04ee LibURL: Expose rust host parsing over FFI
To be used instead of the C++ implementation.
2026-05-28 09:27:41 +02:00
Shannon Booth
b624276e72 LibURL: Remove C++ URLPattern implementation 2026-05-28 09:27:41 +02:00
Shannon Booth
b31e0df363 LibURL: Implement URLPattern in Rust 2026-05-28 09:27:41 +02:00
Shannon Booth
d44ff6628f LibURL: Implement a URL parser in rust 2026-05-28 09:27:41 +02:00
Shannon Booth
079f41b6bb LibURL: Remove unused EncodeURI percent encode set
As it is identical to the ApplicationXWWWFormUrlencoded percent
encode set.
2026-05-28 09:27:41 +02:00
Johan Dahlin
ff57727f73 LibURL: Give resource:// URLs a tuple origin 2026-04-30 07:46:12 +02:00
Timothy Flynn
06796f5f7f LibURL+LibWeb+LibWebView: Convert about:version to a proper WebUI
Passing the browser command line and executable path to every WebContent
process just in case we load about:version always felt a bit weird. We
now use the WebUI framework to load this information on demand.
2026-04-21 06:59:11 -04:00
Timothy Flynn
b544e42809 LibWebView+UI: Add an about:bookmarks page to manage bookmarks
This page renders the bookmarks as a tree and hook context menu events
up to the UI's bookmarks bar context menus to allow editing bookmarks.
Users can also drag-and-drop bookmark items around.
2026-04-09 10:08:06 -04:00
Timothy Flynn
2f3199adbf LibURL+LibWeb: Add a helper to check if a URL is a WebUI URL
Let's not have to know off-hand that we need to update Environments.cpp
when adding a new WebUI. It's more obvious just below where we define
the URLs.
2026-04-09 10:08:06 -04:00
Andreas Kling
34d954e2d7 LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.

The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.

Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-27 17:32:19 +01:00
Shannon Booth
f4f6aefe32 LibURL/Pattern: Ignore extra RegExp captures in match result
execResult may contain additional captures from nested groups
in user-provided regexp parts, exceeding the number of
URLPattern groups.

Fixes a crash in the updated WPT test.

See: https://github.com/whatwg/urlpattern/commit/203d435c32
2026-03-20 11:29:15 +01:00
Shannon Booth
8124a5028c LibURL: Move some Origin helpers out of line
There have been a few times I have wanted to add a debug log in
one of these functions, but currently that causes a massive rebuild.
Let's just move these out of line.
2026-03-01 01:04:10 +01:00
Shannon Booth
b6e5b960fd LibURL: Add a Origin::is_opaque_file_origin helper
We will likely have some of these dotted around the place AD-HOC,
so let's make this a bit more readable when used.
2026-03-01 01:04:10 +01:00
R-Goc
ae5f28fb40 LibTextEncoder/LibURL: Cleanup includes
Cleans up LibURL/Parser.h to use the forwarding header from
LibTextEncoder.
2026-02-26 18:31:57 +01:00
Tim Ledbetter
5893bcf269 LibURL: Strip trailing dot before running the PSL algorithm 2026-02-22 12:07:43 +01:00
Shannon Booth
1be69479a6 LibURL+Elsewhere: Consider file:// origins opaque by default
This aligns our behaviour closer to other browsers, which
_mostly_ consider file scheme URLs as opaque. For test
purposes, allow overriding this behaviour with a commandline
flag.
2026-02-21 23:00:57 +01:00
Shannon Booth
64532bcfa0 LibURL: Add ability to store whether an origin is a file scheme origin 2026-02-21 23:00:57 +01:00
Timothy Flynn
ea32502947 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-21 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2026-02-18 08:02:45 -05:00
Shannon Booth
1c3d503146 LibURL: Remove LibCrypto as a dependency
This was previously a depdency due to the use of
Crypto::get_secure_random for the nonce used for an opaque origin.
Now that this has been moved to AK, we no longer have any dependency
on LibCrypto.
2026-01-26 18:46:59 +01:00
Shannon Booth
c8dc5ea27c LibURL: Optimize parsing of URLs in authority state
Previously the authority state was parsed character-by-character in a
loop, appending each character to a buffer. When an '@' character was
encountered, the entire buffer would be re-processed to extract and
percent-encode the username and password portions.

This created O(n^2) behavior for URLs with multiple '@' characters, as
each '@' would trigger reprocessing of all previously buffered content.

This commit changes the authority state parser to process the authority
section in chunks rather than character-by-character:

1. Find the next delimiter ('@', '/', '?', '#', or '\' for special URLs)
2. Process the entire chunk up to that delimiter at once
3. Directly extract username/password from the chunk without buffering

With an additional change of switching to:
iterator_at_byte_offset_without_validation (which does not have any
loops), this reduces the time complexity to O(n) and the included
test found by fuzzing to actually complete parsing :^)
2026-01-26 18:46:59 +01:00
Shannon Booth
add381fe60 LibURL: Remove redundant radix validation in parse_ipv4_number
AK::parse_number already validates that all characters are valid for
the specified radix.
2026-01-26 18:46:59 +01:00
Shannon Booth
fd01e80286 LibURL: Remove a stray newline 2026-01-26 18:46:59 +01:00
Shannon Booth
b6969fb82d LibURL: Remove default port handling for the IRC schemes
LibURL previously assigned a default port to the IRC schemes,
a carryover from SerenityOS where IRC is supported.

This behavior deviates from the URL Standard and affects URL parsing by
eliding an explicitly specified port when it matches the default (this
is considered a legacy behaviour of the web URL schemes). Remove the IRC
default port to restore spec-compliant behavior.
2026-01-26 18:46:59 +01:00
Shannon Booth
5af269913e LibURL: Implement serialization closer to spec steps
No functional change, just reads a little nicer.
2026-01-26 18:46:59 +01:00
Colleirose
bf7fd80140 LibCrypto+AK: Merge LibCrypto/SecureRandom into AK/Random
AK/Random is already the same as SecureRandom. See PR for more details.

ProcessPrng is used on Windows for compatibility w/ sandboxing measures
See e.g. https://crbug.com/40277768
2026-01-23 15:53:27 +01:00
Arran Ireland
bd82dfa048 AK+LibURL: Use AK::IPv4/6 in Host
This resolves two FIXME comments.
2025-12-31 10:24:56 +01:00
Shannon Booth
89dbdd3411 LibURL: Add domain concept to URL::Origin to fix same-origin-domain
The same-origin domain check always returned true if only the scheme
matched. This was because of missing steps to check for the origin's
domain, which didn't exist. Add this concept to URL::Origin, even
though we do not use it at this stage in document.domain setter.

Co-Authored-By: Luke Wilde <luke@ladybird.org>
2025-12-30 13:02:10 +01:00
Shannon Booth
2c11e03582 LibURL: Return a proper registrable domain if it's missing in the PSL
Instead of '*', which is a nonsensical value. Similar to what we do
for determining the public suffix, if no match could be made via the
PSL algorithm, then take everything after the second dot as
the registrable domain.

This prevents us from considering e.g. b.b.example and
a.example as the same site.
2025-12-30 12:40:27 +01:00
Timothy Flynn
c2365653a5 LibURL: Add a few missing internal page factories 2025-09-18 07:27:24 -04:00
Tete17
658477620a LibWeb/LibURL/LibIPC: Extend createObjectURL to also accept MediaSources
This required some changes in LibURL & LibIPC since it has its own
definition of an BlobURLEntry. For now, we don't have a concrete usage
of MediaSource in LibURL so it is defined as an empty struct.

This removes one FIXME in an idl file.
2025-08-19 23:50:38 +02:00
Idan Horowitz
1f1adb6d7e LibWeb+LibURL: Default empty string paths to URL's path in CookieStore 2025-08-17 22:17:36 +02:00
Shannon Booth
e6235210ff LibURL: Convert to scalar string before URL parsing
URL parsing is expected to take place on well formed unicode
strings.
2025-07-07 06:50:57 -04:00
ayeteadoe
25f5936dee CMake: Rename serenity_* helper functions/macros to ladybird_* 2025-07-03 23:19:41 +02:00
Timothy Flynn
62d9a84b8d AK+Everywhere: Replace custom number parsers with fast_float
Our floating point number parser was based on the fast_float library:
https://github.com/fastfloat/fast_float

However, our implementation only supports 8-bit characters. To support
UTF-16, we will need to be able to convert char16_t-based strings to
numbers as well. This works out-of-the-box with fast_float.

We can also use fast_float for integer parsing.
2025-07-03 09:51:56 -04:00
Shannon Booth
bd67a5afaa LibURL: Differentiate cross site opaque origins
Previously if we had two opaque origins both URLs were
being treated as same site.
2025-06-30 08:06:37 +01:00
Shannon Booth
b49b1b35e4 LibURL: Correct logic for domains not matched by PSL in public_suffix
For the AO defined in the URL specification, in the case the
domain does not match against the PSL, we should be returning
the TLD. This fixes a crash for a bunch of WPT tests using the
Document.domain setter when the test is being served by WPT
locally.

We should be doing similar logic in registrable_domain, but that
unfortunately runs into some other issues, so just leave a FIXME
for now.
2025-06-29 12:47:57 +01:00