Skip to content

Commit

Permalink
slightly less fuzzy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrosenfeld10 committed Feb 10, 2025
1 parent 142c24b commit 7e37da8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions libs/importer/src/importers/msecure-csv-importer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("MSecureCsvImporter.parse", () => {
expect(cipher.card.expiration).toBe("04 / 2029");
expect(cipher.card.code).toBe("444");
expect(cipher.card.cardholderName).toBe("Obi Wan Kenobi");
expect(cipher.notes).toBe("Security code 1234");
expect(cipher.card.brand).toBe("");
});

Expand Down
9 changes: 5 additions & 4 deletions libs/importer/src/importers/msecure-csv-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@ export class MSecureCsvImporter extends BaseImporter implements Importer {
).split("/");
cipher.card.expMonth = month.trim();
cipher.card.expYear = year.trim();
const securityCodeRegex = RegExp("^Security Code\\|.*\\|");
const securityCodeRegex = RegExp("^Security Code\\|\\d*\\|");
const securityCodeEntry = value.find((entry: string) => securityCodeRegex.test(entry));
cipher.card.code = this.getValueOrDefault(
this.splitValueRetainingLastPart(securityCodeEntry),
);

const cardNameRegex = RegExp("^Name on Card\\|.*\\|");
const cardNameRegex = RegExp("^Name on Card\\|\\d*\\|");
const nameOnCardEntry = value.find((entry: string) => entry.match(cardNameRegex));
cipher.card.cardholderName = this.getValueOrDefault(
this.splitValueRetainingLastPart(nameOnCardEntry),
);

cipher.card.brand = this.getValueOrDefault(this.splitValueRetainingLastPart(value[9]), "");

const noteRegex = RegExp("\\|\\d*\\|");
const rawNotes = value
.slice(2)
.filter((entry: string) => !this.isNullOrWhitespace(entry) && !entry.includes("|"));
.filter((entry: string) => !this.isNullOrWhitespace(entry) && !noteRegex.test(entry));
const noteIndexes = [8, 10, 11];
const indexedNotes = noteIndexes
.filter((idx) => value[idx] && value[idx].includes("|"))
.filter((idx) => value[idx] && noteRegex.test(value[idx]))
.map((idx) => value[idx])
.map((val) => {
const key = val.split("|")[0];
Expand Down

0 comments on commit 7e37da8

Please sign in to comment.