Lightpanda: the headless browser designed for AI and automation
webapi: support empty form action
Karl Seguin2e7074d5041a
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zigindex 87359bb0e..4810a9add 100644--- a/src/browser/Frame.zig+++ b/src/browser/Frame.zig@@ -4138,12 +4138,16 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.Forvar buf = std.Io.Writer.Allocating.init(arena.allocator());try form_data.write(arena.allocator(), .{ .encoding = encoding, .charset = charset }, &buf.writer);- var action = blk: {+ var action: []const u8 = blk: {if (submit_button) |s| {if (s.getAttributeSafe(comptime .wrap("formaction"))) |fa| break :blk fa;}- break :blk form_element.getAttributeInterned("action") orelse self.url;+ break :blk form_element.getAttributeInterned("action") orelse "";};+ if (action.len == 0) {+ // An empty action is the form document's URL, fragment included.+ action = form_element.asNode().getDocument(self).getURL(self);+ }var opts = NavigateOpts{.reason = .form,diff --git a/src/browser/tests/frames/form_get.html b/src/browser/tests/frames/form_get.htmlindex e98e9abba..0171f61bc 100644--- a/src/browser/tests/frames/form_get.html+++ b/src/browser/tests/frames/form_get.html@@ -66,3 +66,48 @@});}</script>++<script id=get_empty_action_is_document_url type=module>+ {+ // An empty action is the form document's URL, so its fragment is kept.+ const state = await testing.async();+ const frame = await loadFrame('get_empty_action_frame', 'support/page.html?sort=name#top');++ const form = frame.contentDocument.createElement('form');+ form.setAttribute('action', '');+ form.target = 'get_empty_action_frame';+ form.innerHTML = '<input name=sort value=price>';+ frame.contentDocument.body.appendChild(form);++ frame.onload = () => state.resolve();+ form.submit();++ await state.done(() => {+ testing.expectEqual('?sort=price', frame.contentWindow.location.search);+ testing.expectEqual('#top', frame.contentWindow.location.hash);+ });+ }+</script>++<script id=get_empty_formaction_is_document_url type=module>+ {+ // An empty formaction doesn't fall back to the form's action.+ const state = await testing.async();+ const frame = await loadFrame('get_empty_formaction_frame', 'support/page.html?sort=name#top');++ const form = frame.contentDocument.createElement('form');+ form.action = 'other.html';+ form.target = 'get_empty_formaction_frame';+ form.innerHTML = '<input name=sort value=price><button formaction="">go</button>';+ frame.contentDocument.body.appendChild(form);++ frame.onload = () => state.resolve();+ form.requestSubmit(form.querySelector('button'));++ await state.done(() => {+ testing.expectEqual(true, frame.contentWindow.location.pathname.endsWith('/support/page.html'));+ testing.expectEqual('?sort=price', frame.contentWindow.location.search);+ testing.expectEqual('#top', frame.contentWindow.location.hash);+ });+ }+</script>