{{ message }}
Repository navigation
fix(muyajs): clamp setStart offset to legal range to prevent IndexSizeError (#2800) - #4358
Merged
Merged
Conversation
…eError (#2800) Typing literal `<pre>test</pre>` (or other inline HTML opening tags) caused the renderer to crash: IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 5. The existing clamp in selection/index.js only handled unsigned-integer overflow (offsets near 2^32). The `<pre>` recipe produces a small positive offset that nonetheless exceeds the post-partialRender childNodes count for the paragraph, since the inline HTML token consolidates multiple child spans into one. Extend the clamp to bound the offset by the node's actual child / text length before forwarding to Range.setStart / Range.setEnd / Selection.extend. Regression guard: test/e2e/issue-2800.spec.ts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Contributor
|
Build artifacts for PR #4358: Run: https://github.com/marktext/marktext/actions/runs/26894198483 |
…lampLegalOffset Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Jun 6, 2026
Closed
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.

Summary
<pre>test</pre>(or other inline HTML opening tags) crashed the renderer because the existingsetCursorRangeclamp inpackages/muyajs/lib/selection/index.jsonly guarded against unsigned-int overflow, not against real-but-out-of-range small positive offsets produced by partialRender consolidating childNodesoffsetby the node'schildNodes.length(ortextContent.lengthfor text nodes) before callingRange.setStart/Range.setEnd/Selection.extendpackages/desktop/test/e2e/issue-2800.spec.tsreproduces the original recipe + adjacent inline-HTML variants; red without the fix, green with itCloses
Closes #2800
Test plan
pnpm -C packages/desktop exec playwright test test/e2e/issue-2800.spec.ts— 3/3 pass with this PR (verified red without the fix)crash-range-offset.spec.tsstill green — same crash family, ensures clamp expansion doesn't regress already-guarded recipespnpm run lint,pnpm run typecheckclean🤖 Generated with Claude Code