mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-21 18:42:53 +00:00
LibWeb: Don't strip leading '?' in query initializing a URL
In our implementation of url-initialize, we were invoking the constructor of URLSearchParams: https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams Instead of the 'initialize' AO: https://url.spec.whatwg.org/#urlsearchparams-initialize This has the small difference of stripping any leading '?' from the query (which we are not meant to be doing!).
This commit is contained in:
parent
d7b19b3278
commit
fd4e943e12
Notes:
github-actions[bot]
2024-08-06 22:09:12 +00:00
Author: https://github.com/shannonbooth
Commit: fd4e943e12
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/987
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 34 additions and 2 deletions
|
@ -152,6 +152,17 @@ pathname => '/test'
|
||||||
search => '?test'
|
search => '?test'
|
||||||
searchParams => 'test='
|
searchParams => 'test='
|
||||||
hash => ''
|
hash => ''
|
||||||
|
new URL('??a=b&c=d', 'http://example.org/foo/bar')
|
||||||
|
protocol => 'http:'
|
||||||
|
username => ''
|
||||||
|
password => ''
|
||||||
|
host => 'example.org'
|
||||||
|
hostname => 'example.org'
|
||||||
|
port => ''
|
||||||
|
pathname => '/foo/bar'
|
||||||
|
search => '??a=b&c=d'
|
||||||
|
searchParams => '%3Fa=b&c=d'
|
||||||
|
hash => ''
|
||||||
=========================================
|
=========================================
|
||||||
URL.parse('ftp://serenityos.org:21', undefined)
|
URL.parse('ftp://serenityos.org:21', undefined)
|
||||||
protocol => 'ftp:'
|
protocol => 'ftp:'
|
||||||
|
@ -307,3 +318,14 @@ pathname => '/test'
|
||||||
search => '?test'
|
search => '?test'
|
||||||
searchParams => 'test='
|
searchParams => 'test='
|
||||||
hash => ''
|
hash => ''
|
||||||
|
URL.parse('??a=b&c=d', 'http://example.org/foo/bar')
|
||||||
|
protocol => 'http:'
|
||||||
|
username => ''
|
||||||
|
password => ''
|
||||||
|
host => 'example.org'
|
||||||
|
hostname => 'example.org'
|
||||||
|
port => ''
|
||||||
|
pathname => '/foo/bar'
|
||||||
|
search => '??a=b&c=d'
|
||||||
|
searchParams => '%3Fa=b&c=d'
|
||||||
|
hash => ''
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
{ input: ' \t', base: 'http://ladybird.org/foo/bar' },
|
{ input: ' \t', base: 'http://ladybird.org/foo/bar' },
|
||||||
{ input: '/c:/foo/bar', base: 'file:///c:/baz/qux' },
|
{ input: '/c:/foo/bar', base: 'file:///c:/baz/qux' },
|
||||||
{ input: '', base: 'file:///test?test#test' },
|
{ input: '', base: 'file:///test?test#test' },
|
||||||
|
{ input: '??a=b&c=d', base: 'http://example.org/foo/bar' },
|
||||||
];
|
];
|
||||||
|
|
||||||
for (url of urls) {
|
for (url of urls) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ JS::NonnullGCPtr<DOMURL> DOMURL::initialize_a_url(JS::Realm& realm, URL::URL con
|
||||||
|
|
||||||
// 2. Set url’s URL to urlRecord.
|
// 2. Set url’s URL to urlRecord.
|
||||||
// 3. Set url’s query object to a new URLSearchParams object.
|
// 3. Set url’s query object to a new URLSearchParams object.
|
||||||
auto query_object = MUST(URLSearchParams::construct_impl(realm, query));
|
auto query_object = MUST(URLSearchParams::create(realm, query));
|
||||||
|
|
||||||
// 4. Initialize url’s query object with query.
|
// 4. Initialize url’s query object with query.
|
||||||
auto result_url = DOMURL::create(realm, url_record, move(query_object));
|
auto result_url = DOMURL::create(realm, url_record, move(query_object));
|
||||||
|
|
|
@ -124,6 +124,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create(J
|
||||||
return realm.heap().allocate<URLSearchParams>(realm, realm, move(list));
|
return realm.heap().allocate<URLSearchParams>(realm, realm, move(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://url.spec.whatwg.org/#urlsearchparams-initialize
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create(JS::Realm& realm, StringView init)
|
||||||
|
{
|
||||||
|
// NOTE: We skip the other steps since we know it is a string at this point.
|
||||||
|
// b. Set query’s list to the result of parsing init.
|
||||||
|
return URLSearchParams::create(realm, MUST(url_decode(init)));
|
||||||
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
||||||
// https://url.spec.whatwg.org/#urlsearchparams-initialize
|
// https://url.spec.whatwg.org/#urlsearchparams-initialize
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
|
||||||
|
@ -179,7 +187,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
|
||||||
auto stripped_init = init_string_view.substring_view(init_string_view.starts_with('?'));
|
auto stripped_init = init_string_view.substring_view(init_string_view.starts_with('?'));
|
||||||
|
|
||||||
// b. Set query’s list to the result of parsing init.
|
// b. Set query’s list to the result of parsing init.
|
||||||
return URLSearchParams::create(realm, TRY_OR_THROW_OOM(vm, url_decode(stripped_init)));
|
return URLSearchParams::create(realm, stripped_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-size
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-size
|
||||||
|
|
|
@ -24,6 +24,7 @@ class URLSearchParams : public Bindings::PlatformObject {
|
||||||
JS_DECLARE_ALLOCATOR(URLSearchParams);
|
JS_DECLARE_ALLOCATOR(URLSearchParams);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create(JS::Realm&, StringView);
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create(JS::Realm&, Vector<QueryParam> list);
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create(JS::Realm&, Vector<QueryParam> list);
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue