Skip to content

Commit e6ea03b

Browse files
authored
Merge pull request #35536 from tienifr/fix/35482
fix: Invalid file is downloaded when uploading invalid file and downloading from receipt view
2 parents bdc554f + eca84a4 commit e6ea03b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/components/ReportActionItem/MoneyRequestView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
247247
thumbnail={receiptURIs.thumbnail}
248248
image={receiptURIs.image}
249249
isLocalFile={receiptURIs.isLocalFile}
250+
filename={receiptURIs.filename}
250251
transaction={transaction}
251252
enablePreviewModal
252253
canEditReceipt={canEditReceipt}

src/components/ReportActionItem/ReportActionItemImage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type ReportActionItemImageProps = {
3434

3535
/** whether the receipt can be replaced */
3636
canEditReceipt?: boolean;
37+
38+
/** Filename of attachment */
39+
filename?: string;
3740
};
3841

3942
/**
@@ -42,7 +45,7 @@ type ReportActionItemImageProps = {
4245
* and optional preview modal as well.
4346
*/
4447

45-
function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false}: ReportActionItemImageProps) {
48+
function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false, filename}: ReportActionItemImageProps) {
4649
const styles = useThemeStyles();
4750
const {translate} = useLocalize();
4851
const imageSource = tryResolveUrlFromApiRoot(image ?? '');
@@ -86,7 +89,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr
8689
isReceiptAttachment
8790
canEditReceipt={canEditReceipt}
8891
allowDownload
89-
originalFileName={transaction?.filename}
92+
originalFileName={filename}
9093
>
9194
{({show}) => (
9295
<PressableWithoutFocus

src/libs/ReceiptUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ThumbnailAndImageURI = {
1616
thumbnail: ImageSourcePropType | string | null;
1717
transaction?: Transaction;
1818
isLocalFile?: boolean;
19+
filename?: string;
1920
};
2021

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

4748
if (hasEReceipt) {
48-
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction};
49+
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction, filename};
4950
}
5051

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

5657
if (isReceiptImage) {
57-
return {thumbnail: `${path}.1024.jpg`, image: path};
58+
return {thumbnail: `${path}.1024.jpg`, image: path, filename};
5859
}
5960

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

7475
const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/');
75-
return {thumbnail: image, image: path, isLocalFile};
76+
return {thumbnail: image, image: path, isLocalFile, filename};
7677
}
7778

7879
// eslint-disable-next-line import/prefer-default-export

0 commit comments

Comments
 (0)