mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 03:12:07 -05:00
LibWeb: Resolve HTMLFormElement.action
relative to document base URL
Rather than returning a relative URL, an absolutized URL is now returned relative to the document base URL (cherry picked from commit 48e5d28ec985aeaee565d06a625a0d664b6975d3)
This commit is contained in:
parent
ec91831999
commit
51854c4ffd
3 changed files with 21 additions and 4 deletions
|
@ -0,0 +1,3 @@
|
|||
form.action initial value: http://www.example.com/
|
||||
Final segment of form.action after setting to the empty string: HTMLFormElement-action.html
|
||||
Final segment of form.action after setting to "../test.html": test.html
|
14
Tests/LibWeb/Text/input/HTML/HTMLFormElement-action.html
Normal file
14
Tests/LibWeb/Text/input/HTML/HTMLFormElement-action.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<form action="http://www.example.com/"></form>
|
||||
<script>
|
||||
test(() => {
|
||||
const formElement = document.querySelector('form');
|
||||
println(`form.action initial value: ${formElement.action}`);
|
||||
formElement.action = "";
|
||||
println(`Final segment of form.action after setting to the empty string: ${formElement.action.split('/').pop()}`);
|
||||
formElement.action = "../test.html";
|
||||
println(`Final segment of form.action after setting to "../test.html": ${formElement.action.split('/').pop()}`);
|
||||
formElement.remove();
|
||||
});
|
||||
</script>
|
|
@ -604,12 +604,12 @@ String HTMLFormElement::action() const
|
|||
// The action IDL attribute must reflect the content attribute of the same name, except that on getting, when the
|
||||
// content attribute is missing or its value is the empty string, the element's node document's URL must be returned
|
||||
// instead.
|
||||
if (auto maybe_action = attribute(AttributeNames::action);
|
||||
maybe_action.has_value() && !maybe_action.value().is_empty()) {
|
||||
return maybe_action.value();
|
||||
auto form_action_attribute = attribute(AttributeNames::action);
|
||||
if (!form_action_attribute.has_value() || form_action_attribute.value().is_empty()) {
|
||||
return document().url_string();
|
||||
}
|
||||
|
||||
return MUST(document().url().to_string());
|
||||
return MUST(document().base_url().complete_url(form_action_attribute.value()).to_string());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action
|
||||
|
|
Loading…
Add table
Reference in a new issue