-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Sanitize waypoint fields before sending to API #69549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
87e07f1
4cb9be4
5441e05
b8646eb
0644dc1
04141b6
588d3a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,23 +347,47 @@ function getOnyxDataForRouteRequest( | |
| } | ||
|
|
||
| /** | ||
| * Sanitizes the waypoints by removing the pendingAction property. | ||
| * Sanitizes the waypoints data to only include allowed fields for API requests. | ||
| * Only keeps: name (optional), address, lat, lng | ||
| * | ||
| * @param waypoints - The collection of waypoints to sanitize. | ||
| * @returns The sanitized collection of waypoints. | ||
| * @returns The sanitized collection of waypoints with only allowed fields. | ||
| */ | ||
| function sanitizeRecentWaypoints(waypoints: WaypointCollection): WaypointCollection { | ||
| function sanitizeWaypointsForAPI(waypoints: WaypointCollection): WaypointCollection { | ||
| return Object.entries(waypoints).reduce((acc: WaypointCollection, [key, waypoint]) => { | ||
| if ('pendingAction' in waypoint) { | ||
| const {pendingAction, ...rest} = waypoint; | ||
| acc[key] = rest; | ||
| } else { | ||
| acc[key] = waypoint; | ||
| if (!waypoint) { | ||
| return acc; | ||
| } | ||
|
|
||
| const sanitizedWaypoint: Record<string, string | number> = {}; | ||
|
|
||
| if (waypoint.name !== undefined) { | ||
| sanitizedWaypoint.name = waypoint.name; | ||
| } | ||
| if (waypoint.address !== undefined) { | ||
| sanitizedWaypoint.address = waypoint.address; | ||
| } | ||
| if (waypoint.lat !== undefined) { | ||
| sanitizedWaypoint.lat = waypoint.lat; | ||
| } | ||
| if (waypoint.lng !== undefined) { | ||
| sanitizedWaypoint.lng = waypoint.lng; | ||
| } | ||
|
|
||
| acc[key] = sanitizedWaypoint; | ||
| return acc; | ||
| }, {}); | ||
| } | ||
|
|
||
| /** | ||
| * Sanitizes waypoints and serializes them to a JSON string for API params. | ||
| * Preserves keyForList and other Onyx-only fields by sanitizing at the serialization boundary | ||
| * rather than when building transactionChanges. | ||
| */ | ||
| function stringifyWaypointsForAPI(waypoints: WaypointCollection): string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are introduces [IOU/index.ts:6416] — convertBulkTrackedExpensesToIOU These should use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MelvinBot please address this and update the code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into this and confirmed there are 4 call sites still using the manual
The fix for each: Transaction.ts:399 — direct replacement: - waypoints: JSON.stringify(sanitizeWaypointsForAPI(waypoints)),
+ waypoints: stringifyWaypointsForAPI(waypoints),IOU/index.ts:6416, 6700, 7499 — keep the null guard, replace the stringify call: -const sanitizedWaypointsForBulk = transactionWaypoints ? JSON.stringify(sanitizeWaypointsForAPI(transactionWaypoints)) : undefined;
+const sanitizedWaypointsForBulk = transactionWaypoints ? stringifyWaypointsForAPI(transactionWaypoints) : undefined;(Same pattern for the other two sites.) Also, once the
This comment was marked as duplicate.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MelvinBot Okay, now you are an assignee. Please go ahead and implement this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! Pushed 588d3a1 which replaces all 4 remaining manual
Note: |
||
| return JSON.stringify(sanitizeWaypointsForAPI(waypoints)); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the route for a set of waypoints | ||
| * Used so we can generate a map view of the provided waypoints | ||
|
|
@@ -372,7 +396,7 @@ function sanitizeRecentWaypoints(waypoints: WaypointCollection): WaypointCollect | |
| function getRoute(transactionID: string, waypoints: WaypointCollection, routeType: TransactionState = CONST.TRANSACTION.STATE.CURRENT) { | ||
| const parameters: GetRouteParams = { | ||
| transactionID, | ||
| waypoints: JSON.stringify(sanitizeRecentWaypoints(waypoints)), | ||
| waypoints: stringifyWaypointsForAPI(waypoints), | ||
| }; | ||
|
|
||
| let command; | ||
|
|
@@ -1682,7 +1706,8 @@ export { | |
| setReviewDuplicatesKey, | ||
| abandonReviewDuplicateTransactions, | ||
| openDraftDistanceExpense, | ||
| sanitizeRecentWaypoints, | ||
| sanitizeWaypointsForAPI, | ||
| stringifyWaypointsForAPI, | ||
| getLastModifiedExpense, | ||
| revert, | ||
| changeTransactionsReport, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.