Skip to content

Fix rune iteration bugs#3292

Open
jakebailey wants to merge 1 commit intomainfrom
jabaile/fix-rune-iteration-cases
Open

Fix rune iteration bugs#3292
jakebailey wants to merge 1 commit intomainfrom
jabaile/fix-rune-iteration-cases

Conversation

@jakebailey
Copy link
Copy Markdown
Member

@jakebailey jakebailey commented Mar 29, 2026

I wrote a lint rule to complain on all "ranges over string", then looked at each case. These three were bugs.

Copilot AI review requested due to automatic review settings March 29, 2026 17:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a few incorrect string-iteration behaviors in the Go port that stem from accidentally iterating by runes (UTF-8 code points) when the code expects byte indexing, and updates the affected fourslash baseline output accordingly.

Changes:

  • Fix an off-by-one error in TruncateByRunes so truncation occurs after maxLength runes, not before.
  • Make stack-trace whitespace scanning use byte indexing rather than rune iteration.
  • Fix glob * backtracking to iterate byte positions (not rune start offsets), aligning with the matcher’s byte-oriented indexing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
testdata/baselines/reference/fourslash/documentSymbols/navigationBarItemsMultilineStringIdentifiers3.baseline Updates expected output to reflect corrected truncation behavior.
internal/stringutil/util.go Corrects TruncateByRunes truncation boundary (>=>).
internal/lsp/stack_sanitizer.go Uses byte-index loop when skipping leading whitespace on stack trace lines.
internal/glob/glob.go Changes * backtracking loop to iterate by byte offset rather than rune boundaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants