validate file part bounds to prevent panic (#1612)
This commit is contained in:
@@ -221,22 +221,31 @@ func renderText(
|
|||||||
lastEnd := int64(0)
|
lastEnd := int64(0)
|
||||||
|
|
||||||
// Apply highlighting to filenames and base style to rest of text
|
// Apply highlighting to filenames and base style to rest of text
|
||||||
|
textLen := int64(len(text))
|
||||||
for _, filePart := range fileParts {
|
for _, filePart := range fileParts {
|
||||||
highlight := base.Foreground(t.Secondary())
|
highlight := base.Foreground(t.Secondary())
|
||||||
start, end := filePart.Source.Text.Start, filePart.Source.Text.End
|
start, end := filePart.Source.Text.Start, filePart.Source.Text.End
|
||||||
|
|
||||||
|
if end > textLen {
|
||||||
|
end = textLen
|
||||||
|
}
|
||||||
|
if start > textLen {
|
||||||
|
start = textLen
|
||||||
|
}
|
||||||
|
|
||||||
if start > lastEnd {
|
if start > lastEnd {
|
||||||
result.WriteString(base.Render(text[lastEnd:start]))
|
result.WriteString(base.Render(text[lastEnd:start]))
|
||||||
}
|
}
|
||||||
result.WriteString(highlight.Render(text[start:end]))
|
if start < end {
|
||||||
|
result.WriteString(highlight.Render(text[start:end]))
|
||||||
|
}
|
||||||
|
|
||||||
lastEnd = end
|
lastEnd = end
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastEnd < int64(len(text)) {
|
if lastEnd < textLen {
|
||||||
result.WriteString(base.Render(text[lastEnd:]))
|
result.WriteString(base.Render(text[lastEnd:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
content = base.Width(width - 6).Render(result.String())
|
content = base.Width(width - 6).Render(result.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +253,6 @@ func renderText(
|
|||||||
Local().
|
Local().
|
||||||
Format("02 Jan 2006 03:04 PM")
|
Format("02 Jan 2006 03:04 PM")
|
||||||
if time.Now().Format("02 Jan 2006") == timestamp[:11] {
|
if time.Now().Format("02 Jan 2006") == timestamp[:11] {
|
||||||
// don't show the date if it's today
|
|
||||||
timestamp = timestamp[12:]
|
timestamp = timestamp[12:]
|
||||||
}
|
}
|
||||||
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
||||||
|
|||||||
@@ -303,7 +303,9 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
|||||||
for _, part := range remainingParts {
|
for _, part := range remainingParts {
|
||||||
switch part := part.(type) {
|
switch part := part.(type) {
|
||||||
case opencode.FilePart:
|
case opencode.FilePart:
|
||||||
fileParts = append(fileParts, part)
|
if part.Source.Text.Start >= 0 && part.Source.Text.End >= part.Source.Text.Start {
|
||||||
|
fileParts = append(fileParts, part)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flexItems := []layout.FlexItem{}
|
flexItems := []layout.FlexItem{}
|
||||||
|
|||||||
Reference in New Issue
Block a user