mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:17:34 +00:00
LibWeb: Complete the URL in href_setter() before trying to load it
Also note that setting an invalid URL here should raise a JS exception (and not navigate away). Fixes #4301.
This commit is contained in:
parent
3565d3c60c
commit
d1a5b4d906
3 changed files with 8 additions and 3 deletions
|
@ -70,7 +70,12 @@ JS_DEFINE_NATIVE_SETTER(LocationObject::href_setter)
|
||||||
auto new_href = value.to_string(global_object);
|
auto new_href = value.to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
window.impl().did_set_location_href({}, new_href);
|
auto href_url = window.impl().document().complete_url(new_href);
|
||||||
|
if (!href_url.is_valid()) {
|
||||||
|
vm.throw_exception<JS::URIError>(global_object, String::formatted("Invalid URL '{}'", new_href));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.impl().did_set_location_href({}, href_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_GETTER(LocationObject::pathname_getter)
|
JS_DEFINE_NATIVE_GETTER(LocationObject::pathname_getter)
|
||||||
|
|
|
@ -148,7 +148,7 @@ void Window::cancel_animation_frame(i32 id)
|
||||||
GUI::DisplayLink::unregister_callback(id);
|
GUI::DisplayLink::unregister_callback(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::did_set_location_href(Badge<Bindings::LocationObject>, const String& new_href)
|
void Window::did_set_location_href(Badge<Bindings::LocationObject>, const URL& new_href)
|
||||||
{
|
{
|
||||||
auto* frame = document().frame();
|
auto* frame = document().frame();
|
||||||
if (!frame)
|
if (!frame)
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
void clear_timeout(i32);
|
void clear_timeout(i32);
|
||||||
void clear_interval(i32);
|
void clear_interval(i32);
|
||||||
|
|
||||||
void did_set_location_href(Badge<Bindings::LocationObject>, const String& new_href);
|
void did_set_location_href(Badge<Bindings::LocationObject>, const URL& new_href);
|
||||||
void did_call_location_reload(Badge<Bindings::LocationObject>);
|
void did_call_location_reload(Badge<Bindings::LocationObject>);
|
||||||
|
|
||||||
Bindings::WindowObject* wrapper() { return m_wrapper; }
|
Bindings::WindowObject* wrapper() { return m_wrapper; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue