fix(sections-editor): reject decimal/exponent input on integer schema fields - #5345
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while doing a post-merge sanity check on #5331 (which wired
apps/web/ct/tests/widget-dispatch.ct.tsxinto CI). That test only asserts theinputmodeattribute fornumbervsintegerschema dispatch, so it never caught thatNumberField's partial-input regex (apps/web/src/components/sections-editor/fields/number-field.tsx) accepted a decimal point and exponent for BOTHnumberandintegerJSON-schema types.Failure scenario: any tool/section field with an
integerschema (e.g. a quantity, port, or count) routes throughschema-form.tsx'scase "integer"to the sameNumberFieldasnumber. A user typing1.5or1e5into that field has it accepted keystroke-by-keystroke andonChangefires withNumber("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.tsasisPartialNumericInput(value, isInteger), with a second regex (^[+-]?\d*$) used when the schema isinteger— rejecting.andeoutright instead of only filtering on the shared decimal/exponent-permissive pattern. Behavior fornumberschemas 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 thatnumbermode is unaffected.Reviewer command:
cd apps/web && bun test src/components/sections-editor/fields/partial-number-input.test.tsLocally 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 fornumberschemas is unchanged.isPartialNumericInputinfields/partial-number-input.tswith an integer-safe pattern (no "." or "e").NumberFieldto use the validator whenschema.type === "integer".Written for commit 3e66422. Summary will update on new commits.