Skip to content

Commit

Permalink
fix: disallow floats in the accepted params schema
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Oct 21, 2024
1 parent 677e7e7 commit 2e35984
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/taco/src/conditions/schemas/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { plainStringSchema } from './common';

export const contextParamSchema = z.string().regex(CONTEXT_PARAM_REGEXP);

const paramSchema = z.union([plainStringSchema, z.boolean(), z.number()]);
// TODO: This is too broad, but it's a start
const paramSchema = z.union([plainStringSchema, z.boolean(), z.number().int().nonnegative()]);

export const paramOrContextParamSchema: z.ZodSchema = z.union([
paramSchema,
Expand Down
6 changes: 1 addition & 5 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@ describe('param or context param schema', () => {
expect(paramOrContextParamSchema.safeParse(123).success).toBe(true);
});

it('accepts an floating number', () => {
expect(paramOrContextParamSchema.safeParse(123.4).success).toBe(true);
});

it('accepts a string', () => {
expect(paramOrContextParamSchema.safeParse('deadbeef').success).toBe(true);
});
Expand Down Expand Up @@ -576,7 +572,7 @@ describe('param or context param schema', () => {
1,
[
2,
[true, [1.23, ':hi', '0xdeadbeef'], ':my_name_is', 1],
[true, [123, ':hi', '0xdeadbeef'], ':my_name_is', 1],
':slim_shady',
false,
],
Expand Down

0 comments on commit 2e35984

Please sign in to comment.