Commit Graph

23 Commits

Author SHA1 Message Date
Shannon Booth
e16dfd7aab LibURL: Make percent_encode_after_encoding infallible
(cherry picked from commit 4bb211ba888b8fed9fd3da3163dc6e823d7e3c8a)
2024-10-19 15:26:29 -04:00
Shannon Booth
fdc6730393 LibURL: Update spec comment for validation error in authority state
See: https://github.com/whatwg/url/commit/3e8cd02bb
(cherry picked from commit 84a09476ba9ed34379f82a4a42b361f046c2766a)
2024-10-16 23:56:40 -04:00
Shannon Booth
db4bab8041 LibURL: Make percent_encode return a String
This simplifies a bunch of places which were needing to error check and
convert from a ByteString to String.

(cherry picked from commit 84a7fead0eefd967d4319f4d71c0a0ca3095d2d1)
2024-10-16 23:56:40 -04:00
BenJilks
ab96bf642b LibTextCodec: Implement iso-2022-jp encoder
Implements the `iso-2022-jp` encoder, as specified by
https://encoding.spec.whatwg.org/#iso-2022-jp-encoder

(cherry picked from commit 0ca5675d59dbcb52cedea56729de26b41074024a)
2024-10-15 22:54:51 -04:00
BenJilks
26facdeecc LibWeb: Use text encoding from DOM when parsing URLs
This passes the DOM encoding down to the URL parser, so the correct
encoder can be used.

(cherry picked from commit c1958437f983bb9761661534da34934c8dddcf6f)
2024-10-15 22:54:51 -04:00
BenJilks
4167d1214a LibTextCodec+LibURL: Implement utf-8 and euc-jp encoders
Implements the corresponding encoders, selects the appropriate one when
encoding URL search params. If an encoder for the given encoding could
not be found, fallback to utf-8.

(cherry picked from commit 72d0e3284b604c4c1373fb019250cdf5bd492300)
2024-10-15 22:54:51 -04:00
Shannon Booth
decc664458 LibURL: Fail parsing IPV4 URLs starting with 0x that overflow
Parsing last as an IPV4 number was not returning true in "ends with a
number" as the parsing of that part was overflowing. This means that the
URL is not considered to be an IPv4 address, and is treated as a valid
domain.

Helpfully, the spec also points out in a note that this step is
equivalent to simply checking that the last part ends with 0x followed
by only hex digits - which doesn't suffer from any overflow problem!

Arguably this is an editorial issue in the spec where this should be
clarified a little bit. But for now, fixing this fixes 3 sub tests in
WPT for:

https://wpt.live/url/url-constructor.any.html
(cherry picked from commit 6cac2981fb45498f7e5b84ded2669fb62111da17)
2024-10-15 12:08:50 -04:00
Shannon Booth
e01e49e00d LibURL: Fix heuristic for URL domain parsing IDNA fast path
Our heuristic was a bit too simplistic and would not run through the
ToASCII unicode algorithm which performs some extra validation. This
would cause invalid URLs that should fail to be parsed be mistakenly
accepted.

This fixes 8 tests in: https://wpt.live/url/url-constructor.any.html

(cherry picked from commit db3f1180464eefc841d2eccc5a6b441398dd164d)
2024-10-15 12:08:50 -04:00
Shannon Booth
b40275ce92 LibURL: Don't return early parsing a URL with an empty input
We can't simply use the base URL as it may need to be modified in some
form. For example - for the included test, the fragment was previously
being included in the resulting URL.

This fixes 1 test on https://wpt.live/url/url-constructor.any.html

(cherry picked from commit 1dc4959e915e5f994fb84bf43870a31554ac5d81)
2024-10-15 12:08:50 -04:00
Shannon Booth
544944221f LibURL: Fix method name in debug logging
(cherry picked from commit d161602b6d21e265edc6c23ac4a56d922c22f6b5)
2024-10-15 12:08:50 -04:00
Shannon Booth
8fbf3327eb LibURL: Remove unspecified steps in URL file slash parsing state
There were some extra steps in there which produced wrong results for
relative file URLs.

Fixes 7 test cases in: https://wpt.live/url/url-constructor.any.html

We also need to adjust the test results in TestURL. The behaviour tested
does not match how URL is specified to work as an absolute relative is
given.

(cherry picked from commit 8723f72f0f2ddabbdd2335afca6124f41ba5f267)
2024-10-15 12:08:50 -04:00
Shannon Booth
6c66935420 LibURL: Allow inputs containing only whitespace
The check for:

```
    if (start_index >= end_index)
        return {};
```

To prevent an out of bounds when trimming the start and end of the input
of whitespace was preventing valid URLs (only having whitespace in the
input) from being parsed.

Instead, prevent start_index from ever getting above end_index in the
first place, and don't treat empty inputs as an error.

Fixes one WPT test on:

https://wpt.live/url/url-constructor.any.html
(cherry picked from commit d6af5bf5eb814fcb30959d2bf9fc666cdba716c7)
2024-10-15 12:08:50 -04:00
Shannon Booth
011470bc72 LibURL: Remove FIXME for stripping c0 control or space
The FIXME was not correct - this was done correctly. But let's use a
helper to make the implementation slightly more readable.

(cherry picked from commit 4f5af3e90e52b68803c8ca9e8caa6c61a3a02f18)
2024-10-15 12:08:50 -04:00
Shannon Booth
62040ff7ae LibURL: Remove not particuarly useful NOTE
This doesn't seem like something we will neccessarily do in the URL
class anyway due to performance reasons - unless strictly needed (like
for the DOMURL implementation).

(cherry picked from commit 670ce3ebb17173a2f529cd0ce7cbe8b194c1573a)
2024-10-15 12:08:50 -04:00
Shannon Booth
e1417b2da1 LibURL: Also remove carriage returns from URL input
The definition of an "ASCII tab or newline" also includes U+000D CR.

This fixes 3 subtests in:

https://wpt.live/url/url-constructor.any.html
(cherry picked from commit 41cf9f6fe3f6a36094a8db3ace0733e1e3666092)
2024-10-15 12:08:50 -04:00
Shannon Booth
b4d3a6016e LibURL: Validate for invalid _domain_ code points for non-opaque domains
We were previously not checking for C0 control, U+0025 (%), or U+007F
DELETE.

This makes another good set of URL tests in WPT pass :^)

(cherry picked from commit fdf4f1e887df18bfb51d2c4d8cc469bc75cc016f)
2024-10-15 12:08:50 -04:00
Shannon Booth
2cf67c664d LibURL: Don't consider file:// URL hosts as always opaque
Which was resulting in file URL hosts not being correctly percent
decoded.

(cherry picked from commit a661daea71be0151e4a155db817ff13be9926582)
2024-10-15 12:08:50 -04:00
Shannon Booth
edbf199e5f LibURL: Remove note about bare-boned URL host parsing
It's not so bare-boned any longer :^)

(cherry picked from commit dd7c720657ed6d99328bb785bc65fd5959393e2a)
2024-10-15 12:08:50 -04:00
Andreas Kling
055f4ec64f LibURL: Make URL a copy-on-write type
This patch moves the data members of URL to an internal URL::Data struct
that is also reference-counted. URL then uses a CopyOnWrite<T> template
to give itself copy-on-write behavior.

This means that URL itself is now 8 bytes per instance, and copying is
cheap as long as you don't mutate.

This shrinks many data structures over in LibWeb land. As an example,
CSS::ComputedValues goes from 3024 bytes to 2288 bytes per instance.

(cherry picked from commit 936b76f36e87a6d4cf267c15c95786ef677515fc)
2024-08-13 15:42:19 -04:00
Tim Ledbetter
2519dadbb3 LibURL: Convert ASCII only URLs to lowercase during parsing
This fixes an issue where entering EXAMPLE.COM into the URL bar in the
browser would fail to load as expected.

(cherry picked from commit 1a4b042664f8fddbfa70f009c5873b1f8575bf0b)
2024-06-27 14:00:51 +02:00
Andreas Kling
d568b15acf LibURL: Avoid expensive IDNA::to_ascii() for all-ASCII domain strings
20% of CPU usage when loading https://utah.edu/ was spent doing these
ASCII conversions in URL parsing.
2024-04-05 16:01:10 -06:00
Timothy Flynn
576c2f4f4d LibURL+LibUnicode+LibWebView: Handle punycode directly in LibURL
We had defined punycode handling in LibUnicode when LibURL (AK at the
time) was unable to depend on LibUnicode. This is no longer the case.
2024-03-26 12:25:21 -04:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00