Skip to content

fix(sections-editor): reject decimal/exponent input on integer schema fields - #5345

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/number-field-integer-decimal-w1
Jul 28, 2026
Merged

fix(sections-editor): reject decimal/exponent input on integer schema fields#5345
pedrofrxncx merged 1 commit into
mainfrom
fix/number-field-integer-decimal-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Found while doing a post-merge sanity check on #5331 (which wired apps/web/ct/tests/widget-dispatch.ct.tsx into CI). That test only asserts the inputmode attribute for number vs integer schema dispatch, so it never caught that NumberField's partial-input regex (apps/web/src/components/sections-editor/fields/number-field.tsx) accepted a decimal point and exponent for BOTH number and integer JSON-schema types.

Failure scenario: any tool/section field with an integer schema (e.g. a quantity, port, or count) routes through schema-form.tsx's case "integer" to the same NumberField as number. A user typing 1.5 or 1e5 into that field has it accepted keystroke-by-keystroke and onChange fires with Number("1.5") === 1.5 — a non-integer value gets persisted into org config with nothing downstream re-validating it against the integer schema.

Fix: extracted the partial-number matcher into fields/partial-number-input.ts as isPartialNumericInput(value, isInteger), with a second regex (^[+-]?\d*$) used when the schema is integer — rejecting . and e outright instead of only filtering on the shared decimal/exponent-permissive pattern. Behavior for number schemas is unchanged (same regex, same acceptance set).

Regression test: apps/web/src/components/sections-editor/fields/partial-number-input.test.ts — asserts integer mode rejects "1.5", "1e5", ".5", etc. while still accepting in-progress typing ("", "-", "42"), and that number mode is unaffected.

Reviewer command: cd apps/web && bun test src/components/sections-editor/fields/partial-number-input.test.ts

Locally ran: bun run fmt, cd apps/web && bunx tsc --noEmit (clean), and the targeted test above (3 pass). Full CI covers the rest (including the ct suite this doesn't touch).


Summary by cubic

Rejects decimal and exponent input in integer fields in the sections editor to prevent non-integer values from being saved. Extracted a shared numeric input validator and wired it into NumberField; behavior for number schemas is unchanged.

  • Bug Fixes
    • Added isPartialNumericInput in fields/partial-number-input.ts with an integer-safe pattern (no "." or "e").
    • Updated NumberField to use the validator when schema.type === "integer".
    • Added tests to confirm integer mode rejects decimal/exponent while number mode stays permissive.

Written for commit 3e66422. Summary will update on new commits.

Review in cubic

… fields

NumberField's partial-input regex accepted "." and "e" for both `number`
and `integer` schemas, so typing e.g. "1.5" or "1e5" into an integer-typed
field (widget-dispatch.ct.tsx exercises this exact dispatch) silently
produced a non-integer value with nothing downstream to catch it.
@pedrofrxncx
pedrofrxncx merged commit 1bc231c into main Jul 28, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/number-field-integer-decimal-w1 branch July 28, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant