fix: Avoid false positive matches in enableRegion (#3093) (#3140)

mine
Clément Rezvoy 2025-02-24 02:12:18 +01:00 committed by GitHub
parent f8fbd981d7
commit 8b2939c4ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
var ( var (
keyValRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s(.+)\z`) keyValRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s(.+)\z`)
keyRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s*\z`) keyRX = regexp.MustCompile(`\A(\s*)([\w|\-|\.|\/|\s]+):\s*\z`)
searchRX = regexp.MustCompile(`<<<("search_\d+")>>>(.+)<<<"">>>`)
) )
const ( const (
@ -60,7 +61,7 @@ func colorizeYAML(style config.Yaml, raw string) string {
} }
func enableRegion(str 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) { func saveYAML(dir, name, raw string) (string, error) {

View File

@ -56,6 +56,10 @@ func TestYaml(t *testing.T) {
"Message: Pod The node was low on resource: [DiskPressure].", "Message: Pod The node was low on resource: [DiskPressure].",
"[#4682b4::b]Message[#ffffff::-]: [#ffefd5::]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() s := config.NewStyles()