Skip to content

Commit

Permalink
refactor: move regex to matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Dec 19, 2024
1 parent 6f5f58f commit 5a95320
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
6 changes: 4 additions & 2 deletions dist/autofill-debug.js

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

6 changes: 4 additions & 2 deletions dist/autofill.js

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

5 changes: 1 addition & 4 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,6 @@ class FormAnalyzer {
this.increaseSignalBy(relevantFields.length * 1.5, 'many fields: it is probably not a login');
}

const passwordHintRegex =
/\b(?:password.*?(?:must|should|has to|needs to|can))?\b.*?(?:(at least|minimum|no fewer than)\s+\d+\s+(characters?|letters?|numbers?|special characters?)|(uppercase|lowercase|capital|digit|number|symbol|special character)|\b(no spaces|cannot contain your email|cannot repeat characters|must be unique|case sensitive)\b)/;

// If the form contains password hints, it's highly likely a signup form.
const hasPasswordHints = Array.from(this.form.querySelectorAll('div, span'))
.filter(
Expand All @@ -348,7 +345,7 @@ class FormAnalyzer {
window.getComputedStyle(div).display !== 'none' &&
window.getComputedStyle(div).visibility !== 'hidden',
)
.some((div) => div.textContent && safeRegexTest(passwordHintRegex, div.textContent));
.some((div) => div.textContent && safeRegexTest(this.matching.getDDGMatcherRegex('passwordHintsRegex'), div.textContent));

if (hasPasswordHints) {
this.increaseSignalBy(6, 'Password hints');
Expand Down

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

3 changes: 3 additions & 0 deletions src/Form/matching-config/matching-config-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ const matchingConfiguration = {
// French
'| avec ',
},
passwordHintsRegex: {
match: '\\b(?:password.*?(?:must|should|has to|needs to|can))?\\b.*?(?:(at least|minimum|no fewer than)\\s+\\d+\\s+(characters?|letters?|numbers?|special characters?)|(uppercase|lowercase|capital|digit|number|symbol|special character)|\b(no spaces|cannot contain your email|cannot repeat characters|must be unique|case sensitive)\\b)',
},
submitButtonRegex: {
match:
'submit|send|confirm|save|continue|next|sign|log.?([io])n|buy|purchase|check.?out|subscribe|donate|update|\\bset\\b' +
Expand Down
2 changes: 1 addition & 1 deletion src/Form/matching-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type MatcherTypeNames =
| 'birthdayMonth'
| 'birthdayYear';

type FormMatcherNames = 'loginRegex' | 'signupRegex' | 'conservativeSignupRegex' | 'resetPasswordLink' | 'loginProvidersRegex';
type FormMatcherNames = 'loginRegex' | 'signupRegex' | 'conservativeSignupRegex' | 'resetPasswordLink' | 'loginProvidersRegex' | 'passwordHintsRegex';

type ButtonMatcherNames = 'submitButtonRegex' | 'submitButtonUnlikelyRegex';

Expand Down
6 changes: 4 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.

6 changes: 4 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 5a95320

Please sign in to comment.