1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00
serenity/Userland/Libraries/LibWeb/URL/URL.h
MacDue 8283e8b88c AK: Don't store parts of URLs percent decoded
As noted in serval comments doing this goes against the WC3 spec,
and breaks parsing then re-serializing URLs that contain percent
encoded data, that was not encoded using the same character set as
the serializer.

For example, previously if you had a URL like:

https:://foo.com/what%2F%2F (the path is what + '//' percent encoded)

Creating URL("https:://foo.com/what%2F%2F").serialize() would return:

https://foo.com/what//

Which is incorrect and not the same as the URL we passed. This is
because the re-serializing uses the PercentEncodeSet::Path which
does not include '/'.

Only doing the percent encoding in the setters fixes this, which
is required to navigate to Google Street View (which includes a
percent encoded URL in its URL).

Seems to fix #13477 too
2023-04-12 07:40:22 +02:00

80 lines
2.4 KiB
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2023, networkException <networkexception@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/URL.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/URL/URLSearchParams.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::URL {
class URL : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, Optional<String> const& base = {});
virtual ~URL() override;
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
WebIDL::ExceptionOr<String> href() const;
WebIDL::ExceptionOr<void> set_href(String const&);
WebIDL::ExceptionOr<String> origin() const;
WebIDL::ExceptionOr<String> protocol() const;
WebIDL::ExceptionOr<void> set_protocol(String const&);
WebIDL::ExceptionOr<String> username() const;
void set_username(String const&);
WebIDL::ExceptionOr<String> password() const;
void set_password(String const&);
WebIDL::ExceptionOr<String> host() const;
void set_host(String const&);
WebIDL::ExceptionOr<String> hostname() const;
void set_hostname(String const&);
WebIDL::ExceptionOr<String> port() const;
void set_port(String const&);
WebIDL::ExceptionOr<String> pathname() const;
void set_pathname(String const&);
WebIDL::ExceptionOr<String> search() const;
WebIDL::ExceptionOr<void> set_search(String const&);
URLSearchParams const* search_params() const;
WebIDL::ExceptionOr<String> hash() const;
void set_hash(String const&);
WebIDL::ExceptionOr<String> to_json() const;
void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(query.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes); }
private:
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
AK::URL m_url;
JS::NonnullGCPtr<URLSearchParams> m_query;
};
HTML::Origin url_origin(AK::URL const&);
bool host_is_domain(StringView host);
}