Skip to content

Commit 683b714

Browse files
committed
Try to fix slice panic
1 parent 05c0e2b commit 683b714

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/scanner/scanner.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,9 @@ func SkipTriviaEx(text string, pos int, options *SkipTriviaOptions) int {
20562056
// Keep in sync with couldStartTrivia
20572057
for {
20582058
ch, size := utf8.DecodeRuneInString(text[pos:])
2059+
if size == 0 {
2060+
return pos
2061+
}
20592062
switch ch {
20602063
case '\r':
20612064
if pos+1 < textLen && text[pos+1] == '\n' {
@@ -2143,6 +2146,11 @@ func isConflictMarkerTrivia(text string, pos int) bool {
21432146
panic("pos < 0")
21442147
}
21452148

2149+
// Check bounds before accessing text[pos]
2150+
if pos >= len(text) {
2151+
return false
2152+
}
2153+
21462154
// Conflict markers must be at the start of a line.
21472155
var prev rune
21482156
if pos >= 2 {

0 commit comments

Comments
 (0)