fix: clamp completion range for unclosed string literals#239
Merged
aeschli merged 1 commit intomicrosoft:mainfrom Apr 10, 2026
Merged
Conversation
When an attribute value has an unclosed quote, the replace range could extend past `<` characters after the cursor, causing completions to delete subsequent HTML tags. Clamp valueContentEnd to the cursor offset when the closing quote is missing. Fixes microsoft/vscode#273226
4 tasks
aeschli
approved these changes
Apr 10, 2026
alexr00
approved these changes
Apr 10, 2026
Collaborator
|
@maruthang Thanks! |
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
Fixes microsoft/vscode#273226
Bug: HTML attribute value completions with unclosed quotes would extend the replace range past
<characters, causing subsequent HTML tags to be deleted when accepting a completion.Root Cause: When a quoted attribute value is not closed,
valueContentEndwas set to the end of the scanner token, which could span across<characters into subsequent HTML content. The completion replace range then covered too much text.Fix: When the closing quote is missing (unclosed string literal), clamp
valueContentEndto the current cursor offset so the replace range does not extend into subsequent HTML content.Changes
src/services/htmlCompletion.ts: Added anelsebranch in the attribute value range calculation to setvalueContentEnd = offsetwhen the closing quote is absent, preventing the replace range from spanning past the cursor.src/test/completion.test.ts: Added two regression tests verifying that completions inside unclosed attribute values do not delete subsequent</th>or<td>tags.Testing
src/test/completion.test.tsthat verify completions for unclosed string literals preserve subsequent HTML tags