From 68924827551fc3169c1b9b59c0d7e8bc999a390c Mon Sep 17 00:00:00 2001 From: samu698 Date: Sun, 20 Oct 2024 18:24:24 +0200 Subject: [PATCH] LibWeb: Use correct IDL for HTTPFormElement's method attribute Removed the custom getter and updated the idl so that the attribute is Reflected and Enumerated. --- .../Text/expected/form-method-attribute.txt | 51 +++++++++++++++++++ .../Text/input/form-method-attribute.html | 23 +++++++++ .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 17 ------- .../Libraries/LibWeb/HTML/HTMLFormElement.h | 1 - .../Libraries/LibWeb/HTML/HTMLFormElement.idl | 10 +++- 5 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/form-method-attribute.txt create mode 100644 Tests/LibWeb/Text/input/form-method-attribute.html diff --git a/Tests/LibWeb/Text/expected/form-method-attribute.txt b/Tests/LibWeb/Text/expected/form-method-attribute.txt new file mode 100644 index 00000000000..7d1a5176b07 --- /dev/null +++ b/Tests/LibWeb/Text/expected/form-method-attribute.txt @@ -0,0 +1,51 @@ +form: unset +form.getAttribute('method') == 'null' +form.method == 'get' + +form.setAttribute('method', '') +form.getAttribute('method') == '' +form.method == 'get' + +form.setAttribute('method', 'undefined') +form.getAttribute('method') == 'undefined' +form.method == 'get' + +form.setAttribute('method', 'null') +form.getAttribute('method') == 'null' +form.method == 'get' + +form.setAttribute('method', 'get') +form.getAttribute('method') == 'get' +form.method == 'get' + +form.setAttribute('method', 'post') +form.getAttribute('method') == 'post' +form.method == 'post' + +form.setAttribute('method', 'dialog') +form.getAttribute('method') == 'dialog' +form.method == 'dialog' + +form.setAttribute('method', 'GeT') +form.getAttribute('method') == 'GeT' +form.method == 'get' + +form.setAttribute('method', 'POST') +form.getAttribute('method') == 'POST' +form.method == 'post' + +form.setAttribute('method', 'DIAlog') +form.getAttribute('method') == 'DIAlog' +form.method == 'dialog' + +form.setAttribute('method', 'foo') +form.getAttribute('method') == 'foo' +form.method == 'get' + +form.setAttribute('method', 'xpost') +form.getAttribute('method') == 'xpost' +form.method == 'get' + +form.setAttribute('method', '5%') +form.getAttribute('method') == '5%' +form.method == 'get' diff --git a/Tests/LibWeb/Text/input/form-method-attribute.html b/Tests/LibWeb/Text/input/form-method-attribute.html new file mode 100644 index 00000000000..8e209409398 --- /dev/null +++ b/Tests/LibWeb/Text/input/form-method-attribute.html @@ -0,0 +1,23 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 4be658cc894..636b5a1bd5a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -565,23 +565,6 @@ Vector> HTMLFormElement::get_submittable_elements return submittable_elements; } -// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method -StringView HTMLFormElement::method() const -{ - // The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values. - // FIXME: This should probably be `Reflect` in the IDL. - auto method_state = method_state_from_form_element(*this); - switch (method_state) { - case MethodAttributeState::GET: - return "get"sv; - case MethodAttributeState::POST: - return "post"sv; - case MethodAttributeState::Dialog: - return "dialog"sv; - } - VERIFY_NOT_REACHED(); -} - // https://html.spec.whatwg.org/multipage/forms.html#dom-form-rellist JS::NonnullGCPtr HTMLFormElement::rel_list() { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index 25902854dc2..bb016bccb2b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -88,7 +88,6 @@ public: bool constructing_entry_list() const { return m_constructing_entry_list; } void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; } - StringView method() const; WebIDL::ExceptionOr set_method(String const&); JS::NonnullGCPtr rel_list(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl index 3299d681a49..6ee8d2950c2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl @@ -16,6 +16,14 @@ enum EnctypeAttribute { "text/plain" }; +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method +[MissingValueDefault=get, InvalidValueDefault=get] +enum MethodAttribute { + "get", + "post", + "dialog" +}; + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#selectionmode enum SelectionMode { "select", @@ -35,7 +43,7 @@ interface HTMLFormElement : HTMLElement { [CEReactions, Enumerated=Autocomplete, Reflect] attribute DOMString autocomplete; [CEReactions, Enumerated=EnctypeAttribute, Reflect] attribute DOMString enctype; [CEReactions, Enumerated=EnctypeAttribute, Reflect=enctype] attribute DOMString encoding; - [CEReactions] attribute DOMString method; + [CEReactions, Enumerated=MethodAttribute, Reflect] attribute DOMString method; [CEReactions, Reflect] attribute DOMString name; [CEReactions, Reflect=novalidate] attribute boolean noValidate; [CEReactions, Reflect] attribute DOMString target;