Skip to content

Commit

Permalink
Merge pull request #35536 from tienifr/fix/35482
Browse files Browse the repository at this point in the history
fix: Invalid file is downloaded when uploading invalid file and downloading from receipt view
  • Loading branch information
luacmartins authored Feb 2, 2024
2 parents bdc554f + eca84a4 commit e6ea03b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
thumbnail={receiptURIs.thumbnail}
image={receiptURIs.image}
isLocalFile={receiptURIs.isLocalFile}
filename={receiptURIs.filename}
transaction={transaction}
enablePreviewModal
canEditReceipt={canEditReceipt}
Expand Down
7 changes: 5 additions & 2 deletions src/components/ReportActionItem/ReportActionItemImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type ReportActionItemImageProps = {

/** whether the receipt can be replaced */
canEditReceipt?: boolean;

/** Filename of attachment */
filename?: string;
};

/**
Expand All @@ -42,7 +45,7 @@ type ReportActionItemImageProps = {
* and optional preview modal as well.
*/

function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false}: ReportActionItemImageProps) {
function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false, filename}: ReportActionItemImageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const imageSource = tryResolveUrlFromApiRoot(image ?? '');
Expand Down Expand Up @@ -86,7 +89,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr
isReceiptAttachment
canEditReceipt={canEditReceipt}
allowDownload
originalFileName={transaction?.filename}
originalFileName={filename}
>
{({show}) => (
<PressableWithoutFocus
Expand Down
9 changes: 5 additions & 4 deletions src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ThumbnailAndImageURI = {
thumbnail: ImageSourcePropType | string | null;
transaction?: Transaction;
isLocalFile?: boolean;
filename?: string;
};

type FileNameAndExtension = {
Expand Down Expand Up @@ -45,16 +46,16 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
const hasEReceipt = transaction?.hasEReceipt;

if (hasEReceipt) {
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction};
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction, filename};
}

// For local files, we won't have a thumbnail yet
if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) {
return {thumbnail: null, image: path, isLocalFile: true};
return {thumbnail: null, image: path, isLocalFile: true, filename};
}

if (isReceiptImage) {
return {thumbnail: `${path}.1024.jpg`, image: path};
return {thumbnail: `${path}.1024.jpg`, image: path, filename};
}

const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension;
Expand All @@ -72,7 +73,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
}

const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/');
return {thumbnail: image, image: path, isLocalFile};
return {thumbnail: image, image: path, isLocalFile, filename};
}

// eslint-disable-next-line import/prefer-default-export
Expand Down

0 comments on commit e6ea03b

Please sign in to comment.