Skip to content

Commit

Permalink
fix: add external link check for submit buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Jan 10, 2025
1 parent 9b719c5 commit 58f30a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
14 changes: 9 additions & 5 deletions dist/autofill-debug.js

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

20 changes: 13 additions & 7 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,19 @@ class FormAnalyzer {
const isCustomWebElementLink =
customElements?.get(tagName) != null && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0;

// if an external link matches one of the regexes, we assume the match is not pertinent to the current form
const isElementLink =
(el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') ||
(el.getAttribute('role') || '').toUpperCase() === 'LINK' ||
el.matches('button[class*=secondary]');
const isElementLink = (element) => {
// if an external link matches one of the regexes, we assume the match is not pertinent to the current form
if (element instanceof HTMLAnchorElement) {
return (
(element.href && element.getAttribute('href') !== '#') ||
(element.getAttribute('role') || '').toUpperCase() === 'LINK' ||
element.matches('button[class*=secondary]')
);
}
return false;
};

return isCustomWebElementLink || isElementLink;
return isCustomWebElementLink || isElementLink(el) || isElementLink(el.closest('a'));
}

evaluateElement(el) {
Expand Down Expand Up @@ -281,7 +287,7 @@ class FormAnalyzer {
// Here we don't think this is a submit, so if there is another submit in the form, flip the score
const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]'));
const isSocialButton = /facebook|twitter|google|apple/i.test(string);
shouldFlip = thereIsASubmitButton && !isSocialButton;
shouldFlip = !isSocialButton && (this.isElementExternalLink(el) || thereIsASubmitButton);
}
const strength = likelyASubmit ? 20 : 4;
this.updateSignal({ string, strength, signalType: `button: ${string}`, shouldFlip });
Expand Down
14 changes: 9 additions & 5 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.

0 comments on commit 58f30a4

Please sign in to comment.