From 9c188096d0bce2f4f0daa23f93904b05b79a3a68 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Mar 2023 11:52:40 +0530 Subject: [PATCH] Prevent panics incase highlighting leads to different number of lines --- tools/cmd/diff/collect.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/cmd/diff/collect.go b/tools/cmd/diff/collect.go index 732c03e7d..74ad27a40 100644 --- a/tools/cmd/diff/collect.go +++ b/tools/cmd/diff/collect.go @@ -133,10 +133,14 @@ func lines_for_path(path string) ([]string, error) { } func highlighted_lines_for_path(path string) ([]string, error) { - if ans, found := highlighted_lines_cache.Get(path); found && ans != nil { + plain_lines, err := lines_for_path(path) + if err != nil { + return nil, err + } + if ans, found := highlighted_lines_cache.Get(path); found && len(ans) == len(plain_lines) { return ans, nil } - return lines_for_path(path) + return plain_lines, nil } type Collection struct {