Skip to content

Commit

Permalink
fix: Avoid false positive matches in enableRegion (#3093) (#3140)
Browse files Browse the repository at this point in the history
  • Loading branch information
crezvoy authored Feb 24, 2025
1 parent f8fbd98 commit 8b2939c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/view/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions internal/view/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8b2939c

Please sign in to comment.