summaryrefslogtreecommitdiff
path: root/AK/URLParser.cpp
AgeCommit message (Collapse)Author
2023-01-06AK: Use base URL when the specified URL is emptyThiago Henrique Hupner
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-10-09AK: Fix 'constexpr' attribute on non-constexpr functionBen Wiederhake
is_url_code_point invokes StringView::contains, which never was and cannot become constexpr.
2022-10-09AK+Everywhere: Fix data corruption due to code-point-to-char conversionBen Wiederhake
In particular, StringView::contains(char) is often used with a u32 code point. When this is done, the compiler will for some reason allow data corruption to occur silently. In fact, this is one of two reasons for the following OSS Fuzz issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49184 This is probably a very old bug. In the particular case of URLParser, AK::is_url_code_point got confused: return /* ... */ || "!$&'()*+,-./:;=?@_~"sv.contains(code_point); If code_point is a large code point that happens to have the correct lower bytes, AK::is_url_code_point is then convinced that the given code point is okay, even if it is actually problematic. This commit fixes *only* the silent data corruption due to the erroneous conversion, and does not fully resolve OSS-Fuzz#49184.
2022-09-20AK: Fix bad parsing of some file:/// URLs with base URLAndreas Kling
We were dropping the base URL path components in the resulting URL due to mistakenly determining the input URL to start with a Windows drive letter. Fix this, add a spec link, and a test.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-06AK: Use an enum instead of a bool for String::replace(all_occurences)DexesTTP
This commit has no behavior changes. In particular, this does not fix any of the wrong uses of the previous default parameter (which used to be 'false', meaning "only replace the first occurence in the string"). It simply replaces the default uses by String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-04-10AK: Don't destructively re-encode query strings in the URL parserAndreas Kling
We were decoding and then re-encoding the query string in URLs. This round-trip caused us to lose information about plus ('+') ASCII characters encoded as "%2B".
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-09-14AK: Make URL::m_port an Optional<u16>, Expose raw port getterIdan Horowitz
Our current way of signalling a missing port with m_port == 0 was lacking, as 0 is a valid port number in URLs.
2021-09-14AK: Accept optional url and state override parameters in URLParserIdan Horowitz
These are required in the specification and used by the web's URL built-in, this commit also removes the Badge<AK::URL> from URLParser to allow other classes that need to call the parser directly like the web's URL built-in to do so.
2021-09-11AK: Replace the mutable String::replace API with an immutable versionIdan Horowitz
This removes the awkward String::replace API which was the only String API which mutated the String and replaces it with a new immutable version that returns a new String with the replacements applied. This also fixes a couple of UAFs that were caused by the use of this API. As an optimization an equivalent StringView::replace API was also added to remove an unnecessary String allocations in the format of: `String { view }.replace(...);`
2021-08-06AK: Improve the parsing of data urlsTheFightingCatfish
Improve the parsing of data urls in URLParser to bring it more up-to- spec. At the moment, we cannot parse the components of the MIME type since it is represented as a string, but the spec requires it to be parsed as a "MIME type record".
2021-06-13Userland: Allow building SerenityOS with -funsigned-charGunnar Beutner
Some of the code assumed that chars were always signed while that is not the case on ARM hosts. Also, some of the code tried to use EOF (-1) in a way similar to what fgetc() does, however instead of storing the characters in an int variable a char was used. While this seemed to work it also meant that character 0xFF would be incorrectly seen as an end-of-file. Careful reading of fgetc() reveals that fgetc() stores character data in an int where valid characters are in the range of 0-255 and the EOF value is explicitly outside of that range (usually -1).
2021-06-08AK: Don't create Utf8View from temporary String in URLParserMax Wipfli
This fixes a bug where a Utf8View was created with data from a temporary string, which was immediately deleted. This lead to a use-after-free issue. This also changes most occurences for StringBuilder::to_string in URLParser to use ::string_view(), as the value is passed as StringView const& most of the time anyways. This fixes oss-fuzz issue 34973.
2021-06-05AK: Stop using U+0000 as end of file code point in URL parserMax Wipfli
This changes URL parser to use the 0xFFFFFFFF constant instead of 0 to indicate end of file. This fixes a bug where inputs containing null bytes would terminate the parser early, because they were interpreted as end of file.
2021-06-05AK: Make debugging URLParser easierMax Wipfli
This patch adds a state_name method to URLParser to convert a state to a string. With this, the debugging statements now display the state names. Furthermore, this fixes a bug where non-ASCII code points were formatted as characters, which fails an assertion in the formatting system.
2021-06-05AK: Do not trim away non-ASCII bytes when parsing URLMax Wipfli
Because non-ASCII code points have negative byte values, trimming away control characters requires checking for negative bytes values. This also adds a test case with a URL containing non-ASCII code points.
2021-06-05AK: Update URLParser.{cpp,h} to use east constMax Wipfli
2021-06-03AK: Do not VERIFY on invalid code point bytes in UTF8ViewDexesTTP
The previous behavior was to always VERIFY that the UTF-8 bytes were valid when iterating over the code points of an UTF8View. This change makes it so we instead output the 0xFFFD 'REPLACEMENT CHARACTER' code point when encountering invalid bytes, and keep iterating the view after skipping one byte. Leaving the decision to the consumer would break symmetry with the UTF32View API, which would in turn require heavy refactoring and/or code duplication in generic code such as the one found in Gfx::Painter and the Shell. To make it easier for the consumers to detect the original bytes, we provide a new method on the iterator that returns a Span over the data that has been decoded. This method is immediately used in the TextNode::compute_text_for_rendering method, which previously did this in a ad-hoc waay. This also add tests for the new behavior in TestUtf8.cpp, as well as reinforcements to the existing tests to check if the underlying bytes match up with their expected values.
2021-06-03Everywhere: Replace ctype.h to avoid narrowing conversionsMax Wipfli
This replaces ctype.h with CharacterType.h everywhere I could find issues with narrowing conversions. While using it will probably make sense almost everywhere in the future, the most critical places should have been addressed.
2021-06-01AK: Strip leading/trailing C0-control-or-space in URLs correctlyAndreas Kling
We have to stop scanning once we hit a non-strippable character. Add some tests to cover this.
2021-06-01AK: Rename Utf8CodepointIterator => Utf8CodePointIteratorAndreas Kling
2021-06-01AK: Add a new, spec-compliant URLParserMax Wipfli
This adds a new URL parser, which aims to be compliant with the URL specification (https://url.spec.whatwg.org/). It also contains a rudimentary data URL parser.
2021-06-01AK: Remove URLParserMax Wipfli
This removes URLParser, because its two exposed functions, urlencode() and urldecode(), have been superseded by URL::percent_encode() and URL::percent_decode(). This is in preparation for the introduction of a new URL parser.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-01-31AK: Add optional parameter for excluding chars to urlencode()Linus Groh
2020-12-12AK: Fix urlencode() with high byte valuesConrad Pankoff
Previously urlencode() would encode bytes above 127 incorrectly, printing them as negative hex values.
2020-11-30AK: Fix logic error in urldecode() percent-decodingLinus Groh
We also need to append the raw consumed value if *either* of the two characters after the % isn't a hex digit, not only if *both* aren't. Fixes #4257.
2020-10-08AK: Use new format functions.asynts
2020-06-12AK: Make string-to-number conversion helpers return OptionalAndreas Kling
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-07AK: Add basic percent encoder/decoder (urlencode and urldecode)Andreas Kling