Repository navigation
fix: avoid hangs when slicing empty strings - #392
Open
nithishreddy5771 wants to merge 3 commits into
Open
nithishreddy5771 wants to merge 3 commits into
nithishreddy5771 wants to merge 3 commits into
Conversation
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
On current master,
new MagicString('').slice(-1),.slice(1, 2)and.slice(-2, 1)never return. The empty original has a zero-width chunk at index 0._chunkAtfollowsbyStartorbyEndback to that same chunk when looking outside the original range.Return
undefinedbefore walking for indices below 0 or strictly aboveoriginal.length. Keep index equal to the length eligible for lookup: the empty-original boundary can contain inserted content, and its existing slice behavior is preserved. This also leaves the second caller,_hasRemovedContent, unchanged for valid match positions.Add seven regression/control cases covering 168 empty-original slice calls across negative, zero and positive offsets, explicit and default ends, boundary insertions and integer validation. The regression cases cap map reads so the original bug fails a test rather than hanging the runner.
Validation
All checks used Linux x86_64, Node 22.23.5 and pnpm 12.3.4 with the frozen lockfile. Separate automated validation used the same runtime and OS, not another platform.
--sequence.shuffle.files --sequence.seed=1 --maxWorkers=1pass 494 baseline / 501 patched tests. Shuffled run orders were not asserted identical.git diff --checkpass.There is a pre-existing intermittent legacy
storeNamewarning assertion failure inupdate.test.ts. Separate validation reproduced it in 2 of 8 runs on untouched original source and 2 of 8 on this candidate. Successful complete runs are reported above, not a claim that every run passed. This patch does not change the warning tests; #388 addresses their shared-state ordering. That PR also edits nearby lines in the slice test file, so integration may need a textual rebase if it lands first.Other Node versions, Windows/macOS, performance and downstream consumers were not tested. No production incident or coverage percentage is claimed. This is separate from #384's empty-match replacement fix.
Implemented and tested by an AI assistant on my behalf. The separate check was automated; no human code review is claimed.