diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index a86fd1aaf..b519752af 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -10268,8 +10268,7 @@ class Form { */ getValuesReadyForStorage() { const formValues = this.getRawValues(); - const hasOnlyOneCredential = this.inputs.credentials.size === 1; - return (0, _formatters.prepareFormValuesForStorage)(formValues, hasOnlyOneCredential); + return (0, _formatters.prepareFormValuesForStorage)(formValues); } /** @@ -12104,25 +12103,10 @@ const getMMAndYYYYFromString = expiration => { * @return {boolean} */ exports.getMMAndYYYYFromString = getMMAndYYYYFromString; -const shouldStoreCredentials = (_ref3, hasOnlyOneCredential) => { - let { - credentials - } = _ref3; - if (credentials.password) { - return Boolean(credentials.password); - } else { - return hasOnlyOneCredential && Boolean(credentials.username); - } -}; - -/** - * @param {InternalDataStorageObject} credentials - * @return {boolean} - */ -const shouldStoreIdentities = _ref4 => { +const shouldStoreIdentities = _ref3 => { let { identities - } = _ref4; + } = _ref3; return Boolean((identities.firstName || identities.fullName) && identities.addressStreet && identities.addressCity) || Boolean(identities.emailAddress) || Boolean(identities.phone); }; @@ -12130,10 +12114,10 @@ const shouldStoreIdentities = _ref4 => { * @param {InternalDataStorageObject} credentials * @return {boolean} */ -const shouldStoreCreditCards = _ref5 => { +const shouldStoreCreditCards = _ref4 => { let { creditCards - } = _ref5; + } = _ref4; if (!creditCards.cardNumber) return false; if (creditCards.cardSecurityCode) return true; // Some forms (Amazon) don't have the cvv, so we still save if there's the expiration @@ -12153,11 +12137,10 @@ const formatPhoneNumber = phone => phone.replaceAll(/[^0-9|+]/g, ''); * Formats form data into an object to send to the device for storage * If values are insufficient for a complete entry, they are discarded * @param {InternalDataStorageObject} formValues - * @param {boolean} hasOnlyOneCredential * @return {DataStorageObject} */ exports.formatPhoneNumber = formatPhoneNumber; -const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { +const prepareFormValuesForStorage = formValues => { /** @type {Partial} */ let { credentials, @@ -12170,9 +12153,8 @@ const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { creditCards.cardName = identities?.fullName || formatFullName(identities); } - /** Fixes for credentials **/ - // Don't store if there isn't enough data - if (shouldStoreCredentials(formValues, hasOnlyOneCredential)) { + /** Fixes for credentials */ + if (credentials.username || credentials.password) { // If we don't have a username to match a password, let's see if the email is available if (credentials.password && !credentials.username && identities.emailAddress) { credentials.username = identities.emailAddress; diff --git a/dist/autofill.js b/dist/autofill.js index addd399fa..8c3990b33 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -5905,8 +5905,7 @@ class Form { */ getValuesReadyForStorage() { const formValues = this.getRawValues(); - const hasOnlyOneCredential = this.inputs.credentials.size === 1; - return (0, _formatters.prepareFormValuesForStorage)(formValues, hasOnlyOneCredential); + return (0, _formatters.prepareFormValuesForStorage)(formValues); } /** @@ -7741,25 +7740,10 @@ const getMMAndYYYYFromString = expiration => { * @return {boolean} */ exports.getMMAndYYYYFromString = getMMAndYYYYFromString; -const shouldStoreCredentials = (_ref3, hasOnlyOneCredential) => { - let { - credentials - } = _ref3; - if (credentials.password) { - return Boolean(credentials.password); - } else { - return hasOnlyOneCredential && Boolean(credentials.username); - } -}; - -/** - * @param {InternalDataStorageObject} credentials - * @return {boolean} - */ -const shouldStoreIdentities = _ref4 => { +const shouldStoreIdentities = _ref3 => { let { identities - } = _ref4; + } = _ref3; return Boolean((identities.firstName || identities.fullName) && identities.addressStreet && identities.addressCity) || Boolean(identities.emailAddress) || Boolean(identities.phone); }; @@ -7767,10 +7751,10 @@ const shouldStoreIdentities = _ref4 => { * @param {InternalDataStorageObject} credentials * @return {boolean} */ -const shouldStoreCreditCards = _ref5 => { +const shouldStoreCreditCards = _ref4 => { let { creditCards - } = _ref5; + } = _ref4; if (!creditCards.cardNumber) return false; if (creditCards.cardSecurityCode) return true; // Some forms (Amazon) don't have the cvv, so we still save if there's the expiration @@ -7790,11 +7774,10 @@ const formatPhoneNumber = phone => phone.replaceAll(/[^0-9|+]/g, ''); * Formats form data into an object to send to the device for storage * If values are insufficient for a complete entry, they are discarded * @param {InternalDataStorageObject} formValues - * @param {boolean} hasOnlyOneCredential * @return {DataStorageObject} */ exports.formatPhoneNumber = formatPhoneNumber; -const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { +const prepareFormValuesForStorage = formValues => { /** @type {Partial} */ let { credentials, @@ -7807,9 +7790,8 @@ const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { creditCards.cardName = identities?.fullName || formatFullName(identities); } - /** Fixes for credentials **/ - // Don't store if there isn't enough data - if (shouldStoreCredentials(formValues, hasOnlyOneCredential)) { + /** Fixes for credentials */ + if (credentials.username || credentials.password) { // If we don't have a username to match a password, let's see if the email is available if (credentials.password && !credentials.username && identities.emailAddress) { credentials.username = identities.emailAddress; diff --git a/src/Form/Form.js b/src/Form/Form.js index 5f1f07606..4c426cc0c 100644 --- a/src/Form/Form.js +++ b/src/Form/Form.js @@ -240,8 +240,7 @@ class Form { */ getValuesReadyForStorage() { const formValues = this.getRawValues(); - const hasOnlyOneCredential = this.inputs.credentials.size === 1; - return prepareFormValuesForStorage(formValues, hasOnlyOneCredential); + return prepareFormValuesForStorage(formValues); } /** diff --git a/src/Form/Form.test.js b/src/Form/Form.test.js index b0890a803..4f6492bee 100644 --- a/src/Form/Form.test.js +++ b/src/Form/Form.test.js @@ -84,8 +84,8 @@ describe('Test the form class reading values correctly', () => { `, - expHasValues: false, - expValues: { credentials: undefined }, + expHasValues: true, + expValues: { credentials: { username: 'testUsername' } }, }, { testCase: 'form where the password is <=3 characters long', @@ -95,8 +95,8 @@ describe('Test the form class reading values correctly', () => { `, - expHasValues: false, - expValues: { credentials: undefined }, + expHasValues: true, + expValues: { credentials: { username: 'testUsername' } }, }, { testCase: 'form with hidden email field', diff --git a/src/Form/formatters.js b/src/Form/formatters.js index 52e0fa3c8..a34d9e383 100644 --- a/src/Form/formatters.js +++ b/src/Form/formatters.js @@ -159,18 +159,6 @@ const getMMAndYYYYFromString = (expiration) => { ); }; -/** - * @param {InternalDataStorageObject} credentials - * @return {boolean} - */ -const shouldStoreCredentials = ({ credentials }, hasOnlyOneCredential) => { - if (credentials.password) { - return Boolean(credentials.password); - } else { - return hasOnlyOneCredential && Boolean(credentials.username); - } -}; - /** * @param {InternalDataStorageObject} credentials * @return {boolean} @@ -207,10 +195,9 @@ const formatPhoneNumber = (phone) => phone.replaceAll(/[^0-9|+]/g, ''); * Formats form data into an object to send to the device for storage * If values are insufficient for a complete entry, they are discarded * @param {InternalDataStorageObject} formValues - * @param {boolean} hasOnlyOneCredential * @return {DataStorageObject} */ -const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { +const prepareFormValuesForStorage = (formValues) => { /** @type {Partial} */ let { credentials, identities, creditCards } = formValues; @@ -219,9 +206,8 @@ const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { creditCards.cardName = identities?.fullName || formatFullName(identities); } - /** Fixes for credentials **/ - // Don't store if there isn't enough data - if (shouldStoreCredentials(formValues, hasOnlyOneCredential)) { + /** Fixes for credentials */ + if (credentials.username || credentials.password) { // If we don't have a username to match a password, let's see if the email is available if (credentials.password && !credentials.username && identities.emailAddress) { credentials.username = identities.emailAddress; diff --git a/src/Form/formatters.test.js b/src/Form/formatters.test.js index f4c526cae..0e12b5333 100644 --- a/src/Form/formatters.test.js +++ b/src/Form/formatters.test.js @@ -62,44 +62,35 @@ describe('Can strip phone formatting characters', () => { describe('prepareFormValuesForStorage()', () => { describe('handling credentials', () => { it('accepts for username only', () => { - const values = prepareFormValuesForStorage( - { - credentials: { username: 'dax@example.com' }, - // @ts-ignore - creditCards: {}, - // @ts-ignore - identities: {}, - }, - true, - ); + const values = prepareFormValuesForStorage({ + credentials: { username: 'dax@example.com' }, + // @ts-ignore + creditCards: {}, + // @ts-ignore + identities: {}, + }); expect(values.credentials?.username).toBe('dax@example.com'); }); it('accepts password only', () => { - const values = prepareFormValuesForStorage( - { - // @ts-ignore - credentials: { password: '123456' }, - // @ts-ignore - creditCards: {}, - // @ts-ignore - identities: {}, - }, - false, - ); + const values = prepareFormValuesForStorage({ + // @ts-ignore + credentials: { password: '123456' }, + // @ts-ignore + creditCards: {}, + // @ts-ignore + identities: {}, + }); expect(values.credentials?.password).toBe('123456'); }); it('accepts username+password', () => { const inputCredentials = { username: 'dax@example.com', password: '123456' }; - const values = prepareFormValuesForStorage( - { - credentials: inputCredentials, - // @ts-ignore - creditCards: {}, - // @ts-ignore - identities: {}, - }, - false, - ); + const values = prepareFormValuesForStorage({ + credentials: inputCredentials, + // @ts-ignore + creditCards: {}, + // @ts-ignore + identities: {}, + }); expect(values.credentials).toEqual(inputCredentials); }); }); diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index a86fd1aaf..b519752af 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -10268,8 +10268,7 @@ class Form { */ getValuesReadyForStorage() { const formValues = this.getRawValues(); - const hasOnlyOneCredential = this.inputs.credentials.size === 1; - return (0, _formatters.prepareFormValuesForStorage)(formValues, hasOnlyOneCredential); + return (0, _formatters.prepareFormValuesForStorage)(formValues); } /** @@ -12104,25 +12103,10 @@ const getMMAndYYYYFromString = expiration => { * @return {boolean} */ exports.getMMAndYYYYFromString = getMMAndYYYYFromString; -const shouldStoreCredentials = (_ref3, hasOnlyOneCredential) => { - let { - credentials - } = _ref3; - if (credentials.password) { - return Boolean(credentials.password); - } else { - return hasOnlyOneCredential && Boolean(credentials.username); - } -}; - -/** - * @param {InternalDataStorageObject} credentials - * @return {boolean} - */ -const shouldStoreIdentities = _ref4 => { +const shouldStoreIdentities = _ref3 => { let { identities - } = _ref4; + } = _ref3; return Boolean((identities.firstName || identities.fullName) && identities.addressStreet && identities.addressCity) || Boolean(identities.emailAddress) || Boolean(identities.phone); }; @@ -12130,10 +12114,10 @@ const shouldStoreIdentities = _ref4 => { * @param {InternalDataStorageObject} credentials * @return {boolean} */ -const shouldStoreCreditCards = _ref5 => { +const shouldStoreCreditCards = _ref4 => { let { creditCards - } = _ref5; + } = _ref4; if (!creditCards.cardNumber) return false; if (creditCards.cardSecurityCode) return true; // Some forms (Amazon) don't have the cvv, so we still save if there's the expiration @@ -12153,11 +12137,10 @@ const formatPhoneNumber = phone => phone.replaceAll(/[^0-9|+]/g, ''); * Formats form data into an object to send to the device for storage * If values are insufficient for a complete entry, they are discarded * @param {InternalDataStorageObject} formValues - * @param {boolean} hasOnlyOneCredential * @return {DataStorageObject} */ exports.formatPhoneNumber = formatPhoneNumber; -const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { +const prepareFormValuesForStorage = formValues => { /** @type {Partial} */ let { credentials, @@ -12170,9 +12153,8 @@ const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { creditCards.cardName = identities?.fullName || formatFullName(identities); } - /** Fixes for credentials **/ - // Don't store if there isn't enough data - if (shouldStoreCredentials(formValues, hasOnlyOneCredential)) { + /** Fixes for credentials */ + if (credentials.username || credentials.password) { // If we don't have a username to match a password, let's see if the email is available if (credentials.password && !credentials.username && identities.emailAddress) { credentials.username = identities.emailAddress; diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index addd399fa..8c3990b33 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -5905,8 +5905,7 @@ class Form { */ getValuesReadyForStorage() { const formValues = this.getRawValues(); - const hasOnlyOneCredential = this.inputs.credentials.size === 1; - return (0, _formatters.prepareFormValuesForStorage)(formValues, hasOnlyOneCredential); + return (0, _formatters.prepareFormValuesForStorage)(formValues); } /** @@ -7741,25 +7740,10 @@ const getMMAndYYYYFromString = expiration => { * @return {boolean} */ exports.getMMAndYYYYFromString = getMMAndYYYYFromString; -const shouldStoreCredentials = (_ref3, hasOnlyOneCredential) => { - let { - credentials - } = _ref3; - if (credentials.password) { - return Boolean(credentials.password); - } else { - return hasOnlyOneCredential && Boolean(credentials.username); - } -}; - -/** - * @param {InternalDataStorageObject} credentials - * @return {boolean} - */ -const shouldStoreIdentities = _ref4 => { +const shouldStoreIdentities = _ref3 => { let { identities - } = _ref4; + } = _ref3; return Boolean((identities.firstName || identities.fullName) && identities.addressStreet && identities.addressCity) || Boolean(identities.emailAddress) || Boolean(identities.phone); }; @@ -7767,10 +7751,10 @@ const shouldStoreIdentities = _ref4 => { * @param {InternalDataStorageObject} credentials * @return {boolean} */ -const shouldStoreCreditCards = _ref5 => { +const shouldStoreCreditCards = _ref4 => { let { creditCards - } = _ref5; + } = _ref4; if (!creditCards.cardNumber) return false; if (creditCards.cardSecurityCode) return true; // Some forms (Amazon) don't have the cvv, so we still save if there's the expiration @@ -7790,11 +7774,10 @@ const formatPhoneNumber = phone => phone.replaceAll(/[^0-9|+]/g, ''); * Formats form data into an object to send to the device for storage * If values are insufficient for a complete entry, they are discarded * @param {InternalDataStorageObject} formValues - * @param {boolean} hasOnlyOneCredential * @return {DataStorageObject} */ exports.formatPhoneNumber = formatPhoneNumber; -const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { +const prepareFormValuesForStorage = formValues => { /** @type {Partial} */ let { credentials, @@ -7807,9 +7790,8 @@ const prepareFormValuesForStorage = (formValues, hasOnlyOneCredential) => { creditCards.cardName = identities?.fullName || formatFullName(identities); } - /** Fixes for credentials **/ - // Don't store if there isn't enough data - if (shouldStoreCredentials(formValues, hasOnlyOneCredential)) { + /** Fixes for credentials */ + if (credentials.username || credentials.password) { // If we don't have a username to match a password, let's see if the email is available if (credentials.password && !credentials.username && identities.emailAddress) { credentials.username = identities.emailAddress;