From 116d7a406205e86e8f96dc4d13357165f51d5b3a Mon Sep 17 00:00:00 2001 From: "Ben Mezger (seds)" Date: Wed, 3 Feb 2021 15:06:39 -0300 Subject: [PATCH] Fix: don't check filename by index when listing attachments (#224) * don't check filename by index * Fix: Filter by exact matches --- src/commands/get.command.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index dd251de055..8e96950a4b 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -266,11 +266,17 @@ export class GetCommand extends DownloadCommand { return Response.error('No attachments available for this item.'); } - const attachments = cipher.attachments.filter((a) => a.id.toLowerCase() === id || + let attachments = cipher.attachments.filter((a) => a.id.toLowerCase() === id || (a.fileName != null && a.fileName.toLowerCase().indexOf(id) > -1)); if (attachments.length === 0) { return Response.error('Attachment `' + id + '` was not found.'); } + + const exactMatches = attachments.filter((a) => a.fileName.toLowerCase() === id) + if (exactMatches.length === 1) { + attachments = exactMatches; + } + if (attachments.length > 1) { return Response.multipleResults(attachments.map((a) => a.id)); }