From 5151d47427d88b8ecc15caefc1a74c0355d78dd3 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 2 Jan 2021 22:27:01 -0800 Subject: [PATCH] saveguard oob on markup render --- internal/ui/rich/parser/markup/markup.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/ui/rich/parser/markup/markup.go b/internal/ui/rich/parser/markup/markup.go index 5d95c94..872ae86 100644 --- a/internal/ui/rich/parser/markup/markup.go +++ b/internal/ui/rich/parser/markup/markup.go @@ -262,6 +262,11 @@ func RenderCmplxWithConfig(content text.Rich, cfg RenderConfig) RenderOutput { var lastIndex = 0 for _, index := range appended.Finalize(len(content.Content)) { + // Prevent faulty backend with erroneous insertions. + if index > len(content.Content) { + index = len(content.Content) + } + // Write the content. buf.WriteString(html.EscapeString(content.Content[lastIndex:index])) // Write the tags.