mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
[PM-11588] Bugfix - parse user input value for combined expiry date when creating/adding a card cipher (#11103)
* simplify logic and fix some pattern-matching bugs * add first pass at parsing combined expiry year and month from user input * clean up code * fix broken three-digit parsing case * fix case where splitCombinedDateValues returns empty strings when the input is only a delimiter * fix incorrect expectation of falsy negative integers * clean up code * split out logic from parseYearMonthExpiry * move utils from vault to autofill
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
||||
import { InlineMenuVisibilitySetting } from "@bitwarden/common/autofill/types";
|
||||
import { parseYearMonthExpiry } from "@bitwarden/common/autofill/utils";
|
||||
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import {
|
||||
@@ -1898,11 +1899,21 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
||||
const cardView = new CardView();
|
||||
cardView.cardholderName = card.cardholderName || "";
|
||||
cardView.number = card.number || "";
|
||||
cardView.expMonth = card.expirationMonth || "";
|
||||
cardView.expYear = card.expirationYear || "";
|
||||
cardView.code = card.cvv || "";
|
||||
cardView.brand = card.number ? CardView.getCardBrandByPatterns(card.number) : "";
|
||||
|
||||
// If there's a combined expiration date value and no individual month or year values,
|
||||
// try to parse them from the combined value
|
||||
if (card.expirationDate && !card.expirationMonth && !card.expirationYear) {
|
||||
const [parsedYear, parsedMonth] = parseYearMonthExpiry(card.expirationDate);
|
||||
|
||||
cardView.expMonth = parsedMonth || "";
|
||||
cardView.expYear = parsedYear || "";
|
||||
} else {
|
||||
cardView.expMonth = card.expirationMonth || "";
|
||||
cardView.expYear = card.expirationYear || "";
|
||||
}
|
||||
|
||||
const cipherView = new CipherView();
|
||||
cipherView.name = "";
|
||||
cipherView.folderId = null;
|
||||
|
||||
@@ -300,8 +300,6 @@ export class CreditCardAutoFillConstants {
|
||||
"cb-type",
|
||||
];
|
||||
|
||||
static readonly CardExpiryDateDelimiters: string[] = ["/", "-", ".", " "];
|
||||
|
||||
// Note, these are expressions of user-guidance for the expected expiry date format to be used
|
||||
static readonly CardExpiryDateFormats: CardExpiryDateFormat[] = [
|
||||
// English
|
||||
|
||||
@@ -6,11 +6,15 @@ import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
|
||||
import {
|
||||
AutofillOverlayVisibility,
|
||||
CardExpiryDateDelimiters,
|
||||
} from "@bitwarden/common/autofill/constants";
|
||||
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
||||
import { UserNotificationSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/user-notification-settings.service";
|
||||
import { InlineMenuVisibilitySetting } from "@bitwarden/common/autofill/types";
|
||||
import { normalizeExpiryYearFormat } from "@bitwarden/common/autofill/utils";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||
import { EventType } from "@bitwarden/common/enums";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
@@ -30,7 +34,6 @@ import { CardView } from "@bitwarden/common/vault/models/view/card.view";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { FieldView } from "@bitwarden/common/vault/models/view/field.view";
|
||||
import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view";
|
||||
import { normalizeExpiryYearFormat } from "@bitwarden/common/vault/utils";
|
||||
|
||||
import { BrowserApi } from "../../platform/browser/browser-api";
|
||||
import { ScriptInjectorService } from "../../platform/services/abstractions/script-injector.service";
|
||||
@@ -1397,8 +1400,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
if (expectedExpiryDateFormat) {
|
||||
const { Month, MonthShort, Year } = expiryDateFormatPatterns;
|
||||
|
||||
const expiryDateDelimitersPattern =
|
||||
"\\" + CreditCardAutoFillConstants.CardExpiryDateDelimiters.join("\\");
|
||||
const expiryDateDelimitersPattern = "\\" + CardExpiryDateDelimiters.join("\\");
|
||||
|
||||
// assign the delimiter from the expected format string
|
||||
delimiter =
|
||||
@@ -1450,8 +1452,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
let expectedDateFormat = null;
|
||||
let dateFormatPatterns = null;
|
||||
|
||||
const expiryDateDelimitersPattern =
|
||||
"\\" + CreditCardAutoFillConstants.CardExpiryDateDelimiters.join("\\");
|
||||
const expiryDateDelimitersPattern = "\\" + CardExpiryDateDelimiters.join("\\");
|
||||
|
||||
CreditCardAutoFillConstants.CardExpiryDateFormats.find((dateFormat) => {
|
||||
dateFormatPatterns = dateFormat;
|
||||
@@ -1489,6 +1490,8 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
return false;
|
||||
});
|
||||
});
|
||||
// @TODO if expectedDateFormat is still null, and there is a `pattern` attribute, cycle
|
||||
// through generated formatted values, checking against the provided regex pattern
|
||||
|
||||
return [expectedDateFormat, dateFormatPatterns];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||
import { normalizeExpiryYearFormat } from "@bitwarden/common/autofill/utils";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
@@ -23,7 +24,6 @@ import { CollectionService } from "@bitwarden/common/vault/abstractions/collecti
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
||||
import { normalizeExpiryYearFormat } from "@bitwarden/common/vault/utils";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
import { PasswordRepromptService } from "@bitwarden/vault";
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { EventCollectionService } from "@bitwarden/common/abstractions/event/eve
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { isCardExpired } from "@bitwarden/common/autofill/utils";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||
import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { EventType } from "@bitwarden/common/enums";
|
||||
@@ -24,7 +25,6 @@ import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folde
|
||||
import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { Launchable } from "@bitwarden/common/vault/interfaces/launchable";
|
||||
import { isCardExpired } from "@bitwarden/common/vault/utils";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||
import { PasswordRepromptService } from "@bitwarden/vault";
|
||||
|
||||
Reference in New Issue
Block a user