Commit e39943c4 authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

Don't make anchors cancel form submission when href is javascript

Bug: 1055922
Change-Id: If998e7d3e7f8e07d19a034104c425a3266c79cb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073221
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744751}
parent c817ecf2
...@@ -460,15 +460,18 @@ void HTMLAnchorElement::HandleClick(Event& event) { ...@@ -460,15 +460,18 @@ void HTMLAnchorElement::HandleClick(Event& event) {
// a fragment, in which case pending form submissions should go through. // a fragment, in which case pending form submissions should go through.
// In the case of a target RemoteFrame, don't cancel form submissions // In the case of a target RemoteFrame, don't cancel form submissions
// because we can't be sure what the remote document's urlForBinding is. // because we can't be sure what the remote document's urlForBinding is.
// In the case of href="javascript:", don't cancel form submissions because
// we have always let form submissions take precedence in this case.
// TODO(crbug.com/1053679): Remove this after making anchor navigations // TODO(crbug.com/1053679): Remove this after making anchor navigations
// async like the spec says to do, which will also provide the desired // async like the spec says to do, which will also provide the desired
// behavior. // behavior.
if (LocalFrame* target_local_frame = DynamicTo<LocalFrame>(target_frame)) { if (LocalFrame* target_local_frame = DynamicTo<LocalFrame>(target_frame)) {
KURL document_url = target_local_frame->GetDocument()->urlForBinding(); KURL document_url = target_local_frame->GetDocument()->urlForBinding();
if (!EqualIgnoringFragmentIdentifier(completed_url, document_url) || bool equal_ignoring_fragment =
!completed_url.HasFragmentIdentifier()) { completed_url.HasFragmentIdentifier() &&
EqualIgnoringFragmentIdentifier(completed_url, document_url);
if (!equal_ignoring_fragment && !completed_url.ProtocolIsJavaScript())
GetDocument().CancelFormSubmissions(); GetDocument().CancelFormSubmissions();
}
} }
target_frame->Navigate(frame_request, WebFrameLoadType::kStandard); target_frame->Navigate(frame_request, WebFrameLoadType::kStandard);
......
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/C/#following-hyperlinks">
<title>Anchor element with onclick form submission and href to javascript: url</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- When an anchor element has an onclick handler which submits a form,
the anchor's navigation should occur instead of the form's navigation.
However, if the anchor has an href which returns undefined, then the form
should be submitted. -->
<iframe name="test"></iframe>
<form target="test" action="form.html"></form>
<a id="anchor" target="test" onclick="document.forms[0].submit()" href="javascript:void(0)">Test</a>
<script>
async_test(t => {
const anchor = document.getElementById('anchor');
t.step(() => anchor.click());
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
});
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment