Commit graph

35 commits

Author SHA1 Message Date
xspager dd198e1a29 AK::URL: Fix setting the port number in the case it was the last element of the URL 2020-12-12 20:09:42 +01:00
Brendan Coles 3e0e84dcd1 AK::URL: Check if URL requires a port set to be considered a valid URL
`AK::URL` will now check if the URL requires a port to be set using
`AK::URL.protocol_requires_port(protocol)`.

If the URL does not specify a port, and no default port for the URL
protocol is found with `AK::URL.default_port_for_protocol(protocol)`,
the URL is considered to be invalid.
2020-11-04 19:34:00 +01:00
asynts 1d96d5eea4 AK: Use new format functions. 2020-10-08 09:59:55 +02:00
AnotherTest 5b5ba91335 AK: Add URL::create_with_data() to create data URLs 2020-08-24 18:21:33 +02:00
Andreas Kling fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling ff6de8a169 AK: URL should urldecode data: URL payloads
Otherwise we can end up with percent-encoded nonsense in base64 data
which does not decode correctly.
2020-06-10 17:45:34 +02:00
Andreas Kling ec83555b87 AK: Don't try to complete relative data: URLs 2020-06-07 19:09:03 +02:00
Sergey Bugaev 602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
FalseHonesty b1e4f70173 AK: Fix URL::complete_url behaviour for when a fragment is passed
Previously, passing a fragment string ("#section3") to the complete_url
method would result in a URL that looked like
"file:///home/anon/www/#section3" which was obviously incorrect. Now the
result looks like "file:///home/anon/www/afrag.html#section3".
2020-05-23 11:53:25 +02:00
Conrad Pankoff b5b08fba92 AK: Make sure URL retains trailing slash if present in complete_url 2020-05-17 16:35:42 +02:00
Conrad Pankoff 4214680e76 AK: Set default port in URL to 1965 for gemini protocol 2020-05-17 12:41:38 +02:00
Linus Groh b193670967 AK: Handle "protocol relative URLs" in URL::complete_url() 2020-05-16 21:47:16 +02:00
Andreas Kling 56dbe58bbb AK: Add support for about: URLs 2020-05-10 11:11:48 +02:00
Andreas Kling 3422019e35 AK: Unbreak parsing of file:// URLs with no host
We should still accept file:/// in the URL parser. :^)
2020-05-09 16:47:05 +02:00
Andreas Kling 15601988a4 AK: Allow file:// URLs to have a hostname 2020-05-09 16:14:37 +02:00
Andreas Kling ae047649db AK: Add URL::basename() 2020-05-05 23:56:35 +02:00
Andreas Kling 9e365a6c1c AK: Make URL::to_string() produce a data URL for data URLs :^) 2020-04-26 22:59:12 +02:00
Andreas Kling 389eb1b693 AK: Teach URL how to parse data: URLs :^) 2020-04-26 22:56:58 +02:00
Sergey Bugaev 0aeff9c0c4 AK: Add URL::create_with_url_or_path()
This is an utility to create a URL from a given string, which may be either a
URL such as http://example.com (which will be used as-is), or a file path such
as /etc/fstab (which will be transformed into file:///etc/fstab).
2020-04-19 11:14:26 +02:00
Sergey Bugaev 5a96a6565b AK: Consider more URLs invalid
Not just http or https. This fixes "foo" being recognized as a valid URL with
protocol "foo", empty host and empty path.
2020-04-19 11:14:26 +02:00
Andreas Kling 79eee65372 AK: Add URL::create_with_file_protocol(path)
This is a convenience helper that allows you to easily construct a
file:// URL from an absolute path.
2020-04-18 22:02:04 +02:00
Linus Groh c8d0a2eb3c AK: Parse query and fragment in URL::parse() 2020-04-12 01:18:39 +02:00
Linus Groh 21a61b276b AK: Support fragment in URL 2020-04-12 01:18:39 +02:00
Andreas Kling b1555381ee AK: Recompute URL validity after changing protocol/host/path
This allows you to build URLs by calling setters on an empty URL and
actually get a valid URL at the end.
2020-04-11 23:11:10 +02:00
Andreas Kling ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Andreas Kling 94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling 9641f74310 AK: Teach URL::complete_url() how to resolve URL's starting with "/" 2019-12-10 21:13:00 +01:00
Andreas Kling 6f4c380d95 AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
2019-12-09 17:51:21 +01:00
Andreas Kling a91c17c0eb AK: Add a query string component to URL
It's missing query string parsing from new URLs, but you can set the
query string programmatically, and it will be part of the URL when
serialized through to_string().
2019-11-25 21:21:27 +01:00
Andreas Kling 0405ab91aa LibHTML+AK: Move URL completion from Document to AK::URL
Completing a relative URL based on a base URL seems like generally
useful functionality.
2019-11-19 17:46:36 +01:00
Andreas Kling 835496375f URL: https:// URLs should default to port 443 2019-10-21 17:19:17 +02:00
Andreas Kling f1f928670e URL: Parse URLs that lack a path (e.g "http://serenityos.org") 2019-10-17 23:39:31 +02:00
Andreas Kling bf5a65d934 URL: No need to include ":80" when serializing http:// URLs 2019-10-10 22:06:25 +02:00
Andreas Kling d64c054d25 AK: URL should support file:// URL's
Also add some setters since this class was very setter-less.
2019-10-05 10:14:42 +02:00
Andreas Kling ed43770b2f AK: Add a basic URL class to help us handle URL's
We're gonna need these as we start to write more networking programs.
2019-08-10 17:30:35 +02:00