Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add date field recognition with slashes (#541)

Leendert de Borst0069b8cfc610
diff --git a/browser-extensions/chrome/src/contentScript/Form.ts b/browser-extensions/chrome/src/contentScript/Form.ts
index 823ad0d3a..d7d149f8c 100644
--- a/browser-extensions/chrome/src/contentScript/Form.ts
+++ b/browser-extensions/chrome/src/contentScript/Form.ts
@@ -54,6 +54,12 @@ export function fillCredential(credential: Credential, input: HTMLInputElement)
let formattedDate = '';
switch (form.birthdateField.format) {
+ case 'dd/mm/yyyy':
+ formattedDate = `${day}/${month}/${year}`;
+ break;
+ case 'mm/dd/yyyy':
+ formattedDate = `${month}/${day}/${year}`;
+ break;
case 'dd-mm-yyyy':
formattedDate = `${day}-${month}-${year}`;
break;
diff --git a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts b/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts
index 3d9ee0389..32459dd47 100644
--- a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts
+++ b/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts
@@ -119,6 +119,7 @@ export class FormDetector {
const type = input.type.toLowerCase();
if (!types.includes(type)) continue;
+ // Collect all text attributes to check
const attributes = [
input.type,
input.id,
@@ -127,34 +128,32 @@ export class FormDetector {
input.placeholder
].map(attr => attr?.toLowerCase() || '');
- if (patterns.some(pattern => attributes.some(attr => attr.includes(pattern)))) {
- return input;
+ // Check for associated labels if input has an ID
+ if (input.id) {
+ // Find label with matching 'for' attribute
+ const label = this.document.querySelector(`label[for="${input.id}"]`);
+ if (label) {
+ attributes.push(label.textContent?.toLowerCase() || '');
+ }
}
- }
-
- return null;
- }
- /**
- * Find the password confirmation field that matches the password field.
- */
- private findPasswordConfirmField(passwordField: HTMLInputElement): HTMLInputElement | null {
- const form = passwordField.closest('form');
- const candidates = form
- ? form.querySelectorAll<HTMLInputElement>('input[type="password"]')
- : this.document.querySelectorAll<HTMLInputElement>('input[type="password"]');
-
- for (const input of Array.from(candidates)) {
- if (input === passwordField) continue;
+ // Check for parent label (in case input has a label sibling somewhere up to 3 levels up)
+ let currentElement = input;
+ for (let i = 0; i < 3; i++) {
+ const parentLabel = currentElement.closest('label');
+ if (parentLabel) {
+ attributes.push(parentLabel.textContent?.toLowerCase() || '');
+ break;
+ }
- const attributes = [
- input.id,
- input.name,
- input.className,
- input.placeholder
- ].map(attr => attr?.toLowerCase() || '');
+ // Move up to the parent element
+ if (currentElement.parentElement) {
+ currentElement = currentElement.parentElement as HTMLInputElement;
+ } else {
+ break;
+ }
+ }
- const patterns = ['confirm', 'verification', 'repeat', 'retype', '2', 'verify'];
if (patterns.some(pattern => attributes.some(attr => attr.includes(pattern)))) {
return input;
}
@@ -289,24 +288,26 @@ export class FormDetector {
.join(' ')
// Normalize different types of spaces and separators
.replace(/[\s\u00A0]/g, '')
- .replace(/[/-]/g, '');
-
- // Check for date format patterns
- if (/dd.*mm.*jj/i.test(allText) || /dd.*mm.*yyyy/i.test(allText)) {
- format = 'dd-mm-yyyy';
- } else if (/mm.*dd.*yyyy/i.test(allText)) {
- format = 'mm-dd-yyyy';
- } else if (/yyyy.*mm.*dd/i.test(allText)) {
- format = 'yyyy-mm-dd';
+ // Don't replace separators yet to detect the preferred one
+ .toLowerCase();
+
+ // Check for date format patterns with either slash or dash
+ if (/dd[-/]mm[-/]jj/i.test(allText) || /dd[-/]mm[-/]yyyy/i.test(allText)) {
+ // Determine separator style from the matched pattern
+ format = allText.includes('/') ? 'dd/mm/yyyy' : 'dd-mm-yyyy';
+ } else if (/mm[-/]dd[-/]yyyy/i.test(allText)) {
+ format = allText.includes('/') ? 'mm/dd/yyyy' : 'mm-dd-yyyy';
+ } else if (/yyyy[-/]mm[-/]dd/i.test(allText)) {
+ format = allText.includes('/') ? 'yyyy/mm/dd' : 'yyyy-mm-dd';
}
// Check placeholder as fallback
if (format === 'yyyy-mm-dd' && singleDateField.placeholder) {
- const placeholder = singleDateField.placeholder.toLowerCase().replace(/[\s\u00A0\-/]/g, '');
- if (/ddmm/.test(placeholder)) {
- format = 'dd-mm-yyyy';
- } else if (/mmdd/.test(placeholder)) {
- format = 'mm-dd-yyyy';
+ const placeholder = singleDateField.placeholder.toLowerCase();
+ if (/dd[-/]mm/i.test(placeholder)) {
+ format = placeholder.includes('/') ? 'dd/mm/yyyy' : 'dd-mm-yyyy';
+ } else if (/mm[-/]dd/i.test(placeholder)) {
+ format = placeholder.includes('/') ? 'mm/dd/yyyy' : 'mm-dd-yyyy';
}
}
}
@@ -340,15 +341,17 @@ export class FormDetector {
* Find the gender field in the form.
*/
private findGenderField(form: HTMLFormElement | null): LoginForm['genderField'] {
- // Try to find select element first
- const selectField = form
- ? form.querySelector<HTMLSelectElement>('select[name*="gender"], select[name*="sex"], select[id*="gender"], select[id*="sex"]')
- : null;
-
- if (selectField) {
+ // Try to find select or input element using the shared method
+ const genderField = this.findInputField(
+ form,
+ ['gender', 'sex', 'geslacht', 'aanhef'],
+ ['select']
+ );
+
+ if (genderField?.tagName.toLowerCase() === 'select') {
return {
type: 'select',
- field: selectField
+ field: genderField
};
}
@@ -401,7 +404,7 @@ export class FormDetector {
}
// Fall back to regular text input
- const textField = this.findInputField(form, ['gender', 'sex', 'geslacht'], ['text']);
+ const textField = this.findInputField(form, ['gender', 'sex', 'geslacht', 'aanhef'], ['text']);
return {
type: 'text',
diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.test.ts b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.test.ts
index 745a66ee5..cf780bea8 100644
--- a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.test.ts
+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.test.ts
@@ -162,6 +162,17 @@ describe('FormDetector', () => {
testField(FormField.Email, 'EmailAddress', htmlFile);
});
+ describe('Dutch registration form 5 detection', () => {
+ const htmlFile = 'nl-registration-form5.html';
+
+ testField(FormField.Email, 'input_25_5', htmlFile);
+ testField(FormField.Gender, 'input_25_13', htmlFile);
+ testField(FormField.FirstName, 'input_25_14', htmlFile);
+ testField(FormField.LastName, 'input_25_15', htmlFile);
+ testField(FormField.BirthDate, 'input_25_10', htmlFile);
+ testBirthdateFormat('dd/mm/yyyy', htmlFile);
+ });
+
describe('English registration form 1 detection', () => {
const htmlFile = 'en-registration-form1.html';
diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form5.html b/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form5.html
new file mode 100644
index 000000000..2fe7596d9
--- /dev/null
+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form5.html
@@ -0,0 +1,61 @@
+<!--
+Test form element detection where the input fields themselves have gibberish IDs and only the labels are descriptive.
+This is to test the label detection logic.
+-->
+
+<div class="gf_browser_chrome gform_wrapper gform_legacy_markup_wrapper gform-theme--no-framework" data-form-theme="legacy" data-form-index="0" id="gform_wrapper_25"><form method="post" enctype="multipart/form-data" id="gform_25" action="/nieuwsbrief/" data-formid="25" novalidate="" data-gtm-form-interact-id="0">
+ <div class="gform-body gform_body"><ul id="gform_fields_25" class="gform_fields top_label form_sublabel_below description_below validation_below"><li id="field_25_5" class="gfield gfield--type-email gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_5"><label class="gfield_label gform-field-label gfield_label_before_complex">E-mailadres<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="ginput_complex ginput_container ginput_container_email gform-grid-row" id="input_25_5_container">
+ <span id="input_25_5_1_container" class="ginput_left gform-grid-col gform-grid-col--size-auto">
+ <input class="" type="email" name="input_5" id="input_25_5" value="" aria-required="true" aria-invalid="false" autocomplete="false" data-gtm-form-interact-field-id="0">
+ <label for="input_25_5" class="gform-field-label gform-field-label--type-sub ">E-mailadres invoeren</label>
+ </span>
+ <span id="input_25_5_2_container" class="ginput_right gform-grid-col gform-grid-col--size-auto">
+ <input class="" type="email" name="input_5_2" id="input_25_5_2" value="" aria-required="true" aria-invalid="false" data-gtm-form-interact-field-id="1">
+ <label for="input_25_5_2" class="gform-field-label gform-field-label--type-sub ">E-mailadres bevestigen</label>
+ </span>
+ <div class="gf_clear gf_clear_complex"></div>
+ </div></li><li id="field_25_13" class="gfield gfield--type-select gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_13"><label class="gfield_label gform-field-label" for="input_25_13">Aanhef<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="ginput_container ginput_container_select"><select name="input_13" id="input_25_13" class="medium gfield_select" aria-required="true" aria-invalid="false"><option value="heer">heer</option><option value="mevrouw">mevrouw</option></select><div class="field_icon"><i class="fas fa-sort"></i></div></div></li><li id="field_25_14" class="gfield gfield--type-text gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_14"><label class="gfield_label gform-field-label" for="input_25_14">Voornaam<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="ginput_container ginput_container_text"><input name="input_14" id="input_25_14" type="text" value="" class="medium" aria-required="true" aria-invalid="false" data-gtm-form-interact-field-id="2"></div></li><li id="field_25_15" class="gfield gfield--type-text gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_15"><label class="gfield_label gform-field-label" for="input_25_15">Achternaam<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="ginput_container ginput_container_text"><input name="input_15" id="input_25_15" type="text" value="" class="medium" aria-required="true" aria-invalid="false" data-gtm-form-interact-field-id="3"></div></li><li id="field_25_10" class="gfield gfield--type-date gfield--input-type-datepicker gfield--datepicker-no-icon field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_10"><label class="gfield_label gform-field-label" for="input_25_10">Geboortedatum (niet verplicht)</label><div class="ginput_container ginput_container_date">
+ <input name="input_10" id="input_25_10" type="text" value="" class="datepicker gform-datepicker dmy datepicker_no_icon gdatepicker-no-icon hasDatepicker initialized" placeholder="dd/mm/jjjj" aria-describedby="input_25_10_date_format" aria-invalid="false" data-gtm-form-interact-field-id="4">
+ <span id="input_25_10_date_format" class="screen-reader-text">DD slash MM slash JJJJ</span>
+ <div class="field_icon"><i class="far fa-calendar-alt"></i></div></div>
+</li><li id="field_25_9" class="gfield gfield--type-checkbox gfield--type-choice field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_9"><label class="gfield_label gform-field-label gfield_label_before_complex">Mijn favoriete vakantiebestemming (niet verplicht)</label><div class="ginput_container ginput_container_checkbox"><ul class="gfield_checkbox" id="input_25_9"><li class="gchoice gchoice_25_9_1">
+ <input class="gfield-choice-input" name="input_9.1" type="checkbox" value="Wad" id="choice_25_9_1">
+ <label for="choice_25_9_1" id="label_25_9_1" class="gform-field-label gform-field-label--type-inline">Wad</label>
+ </li><li class="gchoice gchoice_25_9_2">
+ <input class="gfield-choice-input" name="input_9.2" type="checkbox" value="Stad" id="choice_25_9_2">
+ <label for="choice_25_9_2" id="label_25_9_2" class="gform-field-label gform-field-label--type-inline">Stad</label>
+ </li><li class="gchoice gchoice_25_9_3">
+ <input class="gfield-choice-input" name="input_9.3" type="checkbox" value="Landelijk" id="choice_25_9_3">
+ <label for="choice_25_9_3" id="label_25_9_3" class="gform-field-label gform-field-label--type-inline">Landelijk</label>
+ </li></ul></div></li><li id="field_25_4" class="gfield gfield--type-checkbox gfield--type-choice gfield_contains_required field_sublabel_below gfield--has-description field_description_above field_validation_below gfield_visibility_visible" data-js-reload="field_25_4"><label class="gfield_label gform-field-label gfield_label_before_complex">Welke nieuwsbrief wil je van ons ontvangen?<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="gfield_description" id="gfield_description_25_4">Wij gebruiken deze gegevens alleen om je nieuwsbrieven te sturen. Wij vragen je expliciet om akkoord voor het versturen van onze nieuwsbrief.</div><div class="ginput_container ginput_container_checkbox"><ul class="gfield_checkbox" id="input_25_4"><li class="gchoice gchoice_25_4_1">
+ <input class="gfield-choice-input" name="input_4.1" type="checkbox" value="WestCord Hotels" id="choice_25_4_1" aria-describedby="gfield_description_25_4">
+ <label for="choice_25_4_1" id="label_25_4_1" class="gform-field-label gform-field-label--type-inline">WestCord Hotels</label>
+ </li><li class="gchoice gchoice_25_4_2">
+ <input class="gfield-choice-input" name="input_4.2" type="checkbox" value="ss Rotterdam" id="choice_25_4_2">
+ <label for="choice_25_4_2" id="label_25_4_2" class="gform-field-label gform-field-label--type-inline">ss Rotterdam</label>
+ </li><li class="gchoice gchoice_25_4_3">
+ <input class="gfield-choice-input" name="input_4.3" type="checkbox" value="Hotel New York" id="choice_25_4_3">
+ <label for="choice_25_4_3" id="label_25_4_3" class="gform-field-label gform-field-label--type-inline">Hotel New York</label>
+ </li><li class="gchoice gchoice_25_4_4">
+ <input class="gfield-choice-input" name="input_4.4" type="checkbox" value="Hotel Jakarta Amsterdam" id="choice_25_4_4">
+ <label for="choice_25_4_4" id="label_25_4_4" class="gform-field-label gform-field-label--type-inline">Hotel Jakarta Amsterdam</label>
+ </li></ul></div></li><li id="field_25_8" class="gfield gfield--type-checkbox gfield--type-choice gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_8"><label class="gfield_label gform-field-label gfield_label_before_complex">Privacyverklaring<span class="gfield_required"><i class="fas fa-lock"></i></span></label><div class="ginput_container ginput_container_checkbox"><ul class="gfield_checkbox" id="input_25_8"><li class="gchoice gchoice_25_8_1">
+ <input class="gfield-choice-input" name="input_8.1" type="checkbox" value="Ik heb de privacyverklaring gelezen en ga hiermee akkoord" id="choice_25_8_1">
+ <label for="choice_25_8_1" id="label_25_8_1" class="gform-field-label gform-field-label--type-inline">Ik heb de privacyverklaring gelezen en ga hiermee akkoord</label>
+ </li></ul></div></li><li id="field_25_16" class="gfield gfield--type-honeypot gform_validation_container field_sublabel_below gfield--has-description field_description_below field_validation_below gfield_visibility_visible" data-js-reload="field_25_16"><label class="gfield_label gform-field-label" for="input_25_16">Email</label><div class="ginput_container"><input name="input_16" id="input_25_16" type="text" value="" autocomplete="new-password"></div><div class="gfield_description" id="gfield_description_25_16">Dit veld is bedoeld voor validatiedoeleinden en moet niet worden gewijzigd.</div></li></ul></div>
+<div class="gform-footer gform_footer top_label"> <input type="submit" id="gform_submit_button_25" class="gform_button button" onclick="gform.submission.handleButtonClick(this);" value="Versturen">
+<input type="hidden" class="gform_hidden" name="gform_submission_method" data-js="gform_submission_method_25" value="postback">
+<input type="hidden" class="gform_hidden" name="gform_theme" data-js="gform_theme_25" id="gform_theme_25" value="legacy">
+<input type="hidden" class="gform_hidden" name="gform_style_settings" data-js="gform_style_settings_25" id="gform_style_settings_25" value="[]">
+<input type="hidden" class="gform_hidden" name="is_submit_25" value="1">
+<input type="hidden" class="gform_hidden" name="gform_submit" value="25">
+
+<input type="hidden" class="gform_hidden" name="gform_unique_id" value="">
+<input type="hidden" class="gform_hidden" name="state_25" value="WyJbXSIsIjI0NWU2MWRlZWQ0YWI5NTY4MGU2YjA5YTM2NmUxMTViIl0=">
+<input type="hidden" autocomplete="off" class="gform_hidden" name="gform_target_page_number_25" id="gform_target_page_number_25" value="0">
+<input type="hidden" autocomplete="off" class="gform_hidden" name="gform_source_page_number_25" id="gform_source_page_number_25" value="1">
+<input type="hidden" name="gform_field_values" value="">
+
+</div>
+ <p style="display: none !important;" class="akismet-fields-container" data-prefix="ak_"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_1" name="ak_js" value="1739544393837"><script>document.getElementById( "ak_js_1" ).setAttribute( "value", ( new Date() ).getTime() );</script></p></form>
+ </div>
\ No newline at end of file