Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reentrancy protection for 'submit' event #4620

Closed
tkent-google opened this issue May 14, 2019 · 0 comments · Fixed by #4621
Closed

Reentrancy protection for 'submit' event #4620

tkent-google opened this issue May 14, 2019 · 0 comments · Fixed by #4621
Labels
interop Implementations are not interoperable with each other topic: forms

Comments

@tkent-google
Copy link
Contributor

Specification: Form submission algorithm
Found in #4597

Chrome, Firefox, and Safari have a reentrancy protection for submit event. That is to say, they don't allow starting form submission algorithm without submitted from submit() method flag in submit event handlers.

Clicking the first submit button in the following HTML dispatches just one submit event, and click() call does nothing.

On the other hand, f.submit() in submit event should not be ignored.

A possible solution:

  • has in-submit-event flag, initially false.
  • It should be set to true before firing submit event, and reset to false after it.
  • Add "If the submitted from() method flag is not set and in-submit-event flag is true, then return." before step 6 of form submission algorithm.

Note: Edge dispatches two submit events in the example case. It might have a different reentrancy protection.

<!DOCTYPE html>
<body>
<form action="http://www.google.com/search" target="_blank">
 <input type=hidden name=q value=v0>
 <input type=submit>
 <button type=submit>Another submit</button>
</form>
<pre></pre>
<script>
function log(str) {
  document.querySelector('pre').textContent += str + '\n';
}

let f = document.querySelector('form');
f.addEventListener('submit', e => {
  log('Event: ' + e.type);
  let hidden = f.querySelector('[name=q]');
  hidden.value = 'v1';
  document.querySelector('button').click();
  log('Called click()');
  hidden.value = 'v2';
});
</script>
</body>
tkent-google added a commit to tkent-google/html that referenced this issue May 14, 2019
domenic pushed a commit that referenced this issue May 15, 2019
Fixes #4620. This flag prevents reentrancy into the submission algorithm
during submit or invalid events. Blink and Gecko implement this for
submit only; WebKit implements it for both. The specification chooses
WebKit's behavior.

Tests: web-platform-tests/wpt#16811
@domenic domenic added the interop Implementations are not interoperable with each other label May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Implementations are not interoperable with each other topic: forms
Development

Successfully merging a pull request may close this issue.

2 participants