From 8b2939c4ff69a34eb2f6b3d0b772c99917df1c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Rezvoy?= Date: Mon, 24 Feb 2025 02:12:18 +0100 Subject: [PATCH] fix: Avoid false positive matches in enableRegion (#3093) (#3140) --- internal/view/yaml.go | 3 ++- internal/view/yaml_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/view/yaml.go b/internal/view/yaml.go index 828e96e3..a7364e4c 100644 --- a/internal/view/yaml.go +++ b/internal/view/yaml.go @@ -20,6 +20,7 @@ import ( var ( keyValRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s(.+)\z`) keyRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s*\z`) + searchRX = regexp.MustCompile(`<<<("search_\d+")>>>(.+)<<<"">>>`) ) const ( @@ -60,7 +61,7 @@ func colorizeYAML(style config.Yaml, raw string) string { } func enableRegion(str string) string { - return strings.ReplaceAll(strings.ReplaceAll(str, "<<<", "["), ">>>", "]") + return searchRX.ReplaceAllString(str, `[$1]$2[""]`) } func saveYAML(dir, name, raw string) (string, error) { diff --git a/internal/view/yaml_test.go b/internal/view/yaml_test.go index c65d1a0e..e802d3f2 100644 --- a/internal/view/yaml_test.go +++ b/internal/view/yaml_test.go @@ -56,6 +56,10 @@ func TestYaml(t *testing.T) { "Message: Pod The node was low on resource: [DiskPressure].", "[#4682b4::b]Message[#ffffff::-]: [#ffefd5::]Pod The node was low on resource: [DiskPressure[].", }, + { + `data: "<<<"`, + `[#4682b4::b]data[#ffffff::-]: [#ffefd5::]"<<<"`, + }, } s := config.NewStyles()