Lightpanda: the headless browser designed for AI and automation
Get submitter value from the IDL value
Karl Seguinc205e118ebf9
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zigindex abd9c6aaf..e6691e5ae 100644--- a/src/browser/Frame.zig+++ b/src/browser/Frame.zig@@ -3382,9 +3382,6 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.Forform_data.acquireRef();defer form_data.releaseRef(self._page);- const arena = try self._session.getArena(.medium, "submitForm");- errdefer self._session.releaseArena(arena);-// Per HTML spec form-submission algorithm, when the submitter is a submit// button, its formaction/formmethod/formenctype attributes override the// form's corresponding attributes (matching how formtarget is honored above).@@ -3402,7 +3399,6 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.Forbreak :blk form_element.getAttributeSafe(comptime .wrap("method"));};const method = Element.Html.Form.normalizeMethod(method_attr, "get");- const is_post = std.mem.eql(u8, method, "post");// Per the HTML form-submission algorithm, the dialog method closes the// form's nearest ancestor dialog with the submitter's value and performs no@@ -3410,25 +3406,30 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For// both reloads the page and leaves the dialog open forever.// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithmif (std.mem.eql(u8, method, "dialog")) {+ // A submit button always has a value (empty when unset); with no+ // submitter at all the dialog's existing returnValue is left untouched.+ const result: ?[]const u8 = if (submit_button) |s| blk: {+ if (s.is(Element.Html.Form.Input)) |input| {+ break :blk input.getValue();+ }+ // if not an Input, it has to be a Button (checked above by isSubmitButton)+ break :blk s.as(Element.Html.Form.Button).getValue();+ } else null;+var ancestor: ?*Element = form_element;while (ancestor) |el| : (ancestor = el.parentElement()) {const dialog = el.is(Element.Html.Dialog) orelse continue;- // A submit button always has a value (empty when the attribute is- // absent); with no submitter at all the dialog's existing- // returnValue is left untouched.- const result: ?[]const u8 = if (submit_button) |s|- s.getAttributeSafe(comptime .wrap("value")) orelse ""- else- null;try dialog.close(result, self);break;}- // Nothing is navigated, so the arena reserved for the request body goes- // unused — the errdefer above only covers the error path.- self._session.releaseArena(arena);return;}+ const is_post = std.mem.eql(u8, method, "post");++ const arena = try self._session.getArena(.medium, "submitForm");+ errdefer self._session.releaseArena(arena);+// Get charset from accept-charset attribute or fall back to document charsetconst charset: []const u8 = blk: {if (form_element.getAttributeSafe(.wrap("accept-charset"))) |ac| {