Skip to content

Commit

Permalink
fix: can save view with no order
Browse files Browse the repository at this point in the history
`-Infinity` was passed over the API if all views were deleted, and a new
one created.

Unfortunately Prisma serializes `-Infinity` as null
(prisma/prisma#19966 (comment)),
so this API request was able to save as null in the db, rather than
erroring as out of integer bounds.

Added `.finite()` to the zod schema to prevent this possibility in the
future.

No other `number`s in schema allow null, so this is currently the only
field that can have this issue, but we'll need to keep an eye out for
it. `int`s that are conditionally `null` are susceptable.
  • Loading branch information
keyserj committed Dec 19, 2024
1 parent f2701b0 commit dc1d897
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const savedViewSchema = z.object({
"Title may only contain alphanumeric characters, spaces, and dashes, and cannot begin or end with a space or dash.",
)
.optional(),
order: z.number().optional(),
order: z.number().safe().optional(),
viewState: z.object({}).passthrough(), // TODO: extract view options from web/ so we can have type safety here
});

Expand Down
3 changes: 2 additions & 1 deletion src/web/view/quickViewStore/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const createView = () => {
id: newViewId,
type: "quick",
title: newTitle,
order: Math.max(...state.views.map((view) => view.order)) + 1,
// provide -1 by default to `Math.max` because otherwise it returns -Infinity with no arguments
order: Math.max(-1, ...state.views.map((view) => view.order)) + 1,
viewState: currentView,
};

Expand Down

0 comments on commit dc1d897

Please sign in to comment.