Skip to content

Commit fcb0605

Browse files
authored
Merge pull request #55321 from CyberAndrii/55240-Improve-checks-for-receipt-file-detection
2 parents 3e932ed + 26a0cb6 commit fcb0605

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

src/libs/actions/IOU.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
navigateToStartMoneyRequestStep,
4747
updateIOUOwnerAndTotal,
4848
} from '@libs/IOUUtils';
49+
import isFileUploadable from '@libs/isFileUploadable';
4950
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
5051
import * as Localize from '@libs/Localize';
5152
import Log from '@libs/Log';
@@ -4430,7 +4431,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
44304431
const workspaceParams =
44314432
isPolicyExpenseChatReportUtil(chatReport) && chatReport.policyID
44324433
? {
4433-
receipt: receipt instanceof Blob ? receipt : undefined,
4434+
receipt: isFileUploadable(receipt) ? receipt : undefined,
44344435
category,
44354436
tag,
44364437
taxCode,
@@ -4482,7 +4483,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
44824483
createdChatReportActionID,
44834484
createdIOUReportActionID,
44844485
reportPreviewReportActionID: reportPreviewAction.reportActionID,
4485-
receipt: receipt instanceof Blob ? receipt : undefined,
4486+
receipt: isFileUploadable(receipt) ? receipt : undefined,
44864487
receiptState: receipt?.state,
44874488
category,
44884489
tag,
@@ -4752,7 +4753,7 @@ function trackExpense(
47524753
category,
47534754
tag,
47544755
billable,
4755-
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
4756+
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
47564757
waypoints: sanitizedWaypoints,
47574758
customUnitRateID: mileageRate,
47584759
};
@@ -4797,7 +4798,7 @@ function trackExpense(
47974798
category,
47984799
tag,
47994800
billable,
4800-
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
4801+
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
48014802
waypoints: sanitizedWaypoints,
48024803
customUnitRateID: mileageRate,
48034804
};
@@ -4838,7 +4839,7 @@ function trackExpense(
48384839
createdChatReportActionID,
48394840
createdIOUReportActionID,
48404841
reportPreviewReportActionID: reportPreviewAction?.reportActionID,
4841-
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
4842+
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
48424843
receiptState: trackedReceipt?.state,
48434844
category,
48444845
tag,
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type {FileObject} from '@components/AttachmentModal';
2+
3+
function isFileUploadable(file: FileObject | undefined): boolean {
4+
// Native platforms only require the object to include the `uri` property.
5+
// Optionally, it can also have a `name` and `type` properties.
6+
// On other platforms, the file must be an instance of `Blob` or one of its subclasses.
7+
return !!file && 'uri' in file && !!file.uri && typeof file.uri === 'string';
8+
}
9+
10+
export default isFileUploadable;

src/libs/isFileUploadable/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type {FileObject} from '@components/AttachmentModal';
2+
3+
function isFileUploadable(file: FileObject | undefined): boolean {
4+
return file instanceof Blob;
5+
}
6+
7+
export default isFileUploadable;

src/libs/validateFormDataParameter.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import CONST from '@src/CONST';
2-
import getPlatform from './getPlatform';
3-
4-
const platform = getPlatform();
5-
const isNativePlatform = platform === CONST.PLATFORM.ANDROID || platform === CONST.PLATFORM.IOS;
1+
import isFileUploadable from './isFileUploadable';
62

73
/**
84
* Ensures no value of type `object` other than null, Blob, its subclasses, or {uri: string} (native platforms only) is passed to XMLHttpRequest.
@@ -19,10 +15,7 @@ function validateFormDataParameter(command: string, key: string, value: unknown)
1915
return value.every((element) => isValid(element, false));
2016
}
2117
if (isTopLevel) {
22-
// Native platforms only require the value to include the `uri` property.
23-
// Optionally, it can also have a `name` and `type` props.
24-
// On other platforms, the value must be an instance of `Blob`.
25-
return isNativePlatform ? 'uri' in value && !!value.uri : value instanceof Blob;
18+
return isFileUploadable(value);
2619
}
2720
return false;
2821
};

0 commit comments

Comments
 (0)