[diffs/edit] Sanitize malformed position components in normalizePosition#986
Merged
Conversation
Math.min/max pass NaN straight through and fractional indexes break the integer-keyed line-offset lookup, so a NaN (or fractional) line/character resolved to a NaN offset and the degenerate edit range swallowed the entire document — an insert with one malformed component silently erased everything else. normalizePosition now sanitizes before clamping: NaN and -Infinity act as 0, fractions floor, +Infinity clamps to the max. Every position-taking API funnels through it (offsetAt, resolveEdit), so all edit paths are covered. Flips the two malformed-position pins to permanent regression tests with exact expectations; pinned known-bug count drops to 30. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
necolas
approved these changes
Jul 14, 2026
amadeus
approved these changes
Jul 14, 2026
amadeus
left a comment
Member
There was a problem hiding this comment.
lgtm. could there be a valid reason to throw in this situation? or is there something about the API where a user could provide bad data? But probably not a big deal overall
Contributor
Author
|
mm don't think so |
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.
What
Fixes the worst bug found by the editor-behavior test audit: an edit whose range carries a
NaN(or fractional)line/charactercomponent silently replaced the entire document with the inserted text.Repro before this fix:
Why
normalizePositionclamped with bareMath.max(0, Math.min(...)), which passesNaNstraight through, and fractional indexes survived the clamps only to break the integer-keyed line-offset lookup. Either way the resolved offset becameNaN, and aNaN-ranged edit degenerates into a whole-document replace.Fix
normalizePositionsanitizes components before clamping, consistent with its existing silent-clamp policy for out-of-range values:NaNand-Infinityact as 0, fractions floor,+Infinityclamps to the max. Every position-taking API funnels through it (offsetAt,#resolveEdit), so all edit paths are covered in one place.+Infinitybehavior is byte-identical to before (already clamped correctly by accident).Tests
test.failingpins for this bug flip to permanent regression tests with exact expected outputs (insertion lands at the sanitized position, no content lost).Infinitydivergence pin is unchanged and still passes.test/README.mdknown-bug inventory: 32 → 30.First PR of the failing-test burn-down; next up is the history-equivalence cluster (7 pins).
🤖 Generated with Claude Code