Skip to content

Commit

Permalink
fix: check if form elements are iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Aug 8, 2024
1 parent a3bab7d commit 2b779cc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
5 changes: 3 additions & 2 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,17 @@ class Form {
} else {
/** @type {Element[] | NodeList} */
let foundInputs = []

if (this.form instanceof HTMLFormElement) {
// Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable.
if (
this.form instanceof HTMLFormElement &&
this.form.elements != null &&
Symbol.iterator in Object(this.form.elements)
) {
// For form elements we use .elements to catch fields outside the form itself using the form attribute.
// It also catches all elements when the markup is broken.
// We use .filter to avoid fieldset, button, textarea etc.
const formElements = [...this.form.elements].filter((el) => el.matches(selector))
// If there are not form elements, we try to look for all
// If there are no form elements, we try to look for all
// enclosed elements within the form.
foundInputs = formElements.length > 0
? formElements
Expand Down
5 changes: 3 additions & 2 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b779cc

Please sign in to comment.