1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Strip ANSI color codes from notifications (#2508)

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Costas Drogos
2023-08-29 19:24:09 +02:00
committed by GitHub
parent d8047eb112
commit 8bf996bb8e
2 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
package notifications
import "testing"
func Test_stripAnsiColorsValid(t *testing.T) {
coloredStr := "\x1b[0133myellow\x1b[0m" // 33 == yellow
nonColoredStr := "yellow"
s := stripAnsiColors(coloredStr)
if s != nonColoredStr {
t.Errorf("stripAnsiColors() stripped %q different from %q", coloredStr, nonColoredStr)
}
}
func Test_stripAnsiColorsInvalid(t *testing.T) {
coloredStr := "\x1b[01AAmyellow\x1b[0m" // AA not a real color
nonColoredStr := "yellow"
s := stripAnsiColors(coloredStr)
if s == nonColoredStr {
t.Errorf("stripAnsiColors() stripped %q should be different from %q", coloredStr, nonColoredStr)
}
}