From 011a4ab8f58743370935e55bf043dea69f5953d0 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 26 Jan 2024 17:07:44 +0100 Subject: [PATCH] fix(ansi): allow usage of < and > in text with overrides --- src/ansi/ansi_writer.go | 2 +- src/ansi/ansi_writer_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go index b9b7adc216db..f33f5494eb80 100644 --- a/src/ansi/ansi_writer.go +++ b/src/ansi/ansi_writer.go @@ -54,7 +54,7 @@ const ( // Foreground takes the current segment's foreground color Foreground = "foreground" - AnchorRegex = `^(?P<(?P[^,>]+)?,?(?P[^>]+)?>)` + AnchorRegex = `^(?P<(?P[^,<>]+)?,?(?P[^<>]+)?>)` colorise = "\x1b[%sm" transparent = "\x1b[0m\x1b[%s;49m\x1b[7m" transparentEnd = "\x1b[27m" diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go index b5b8a2abec0f..7e1881b9ab1b 100644 --- a/src/ansi/ansi_writer_test.go +++ b/src/ansi/ansi_writer_test.go @@ -206,6 +206,12 @@ func TestWriteANSIColors(t *testing.T) { Expected: "\x1b[47m\x1b[30mhome\x1b[0m\x1b[37;49m\x1b[7m / \x1b[27m\x1b[47m\x1b[30mcode\x1b[0m\x1b[37;49m\x1b[7m / \x1b[27m\x1b[47m\x1b[30msrc \x1b[0m", Colors: &Colors{Foreground: "black", Background: "white"}, }, + { + Case: "Larger than and less than symbols", + Input: "<><", + Expected: "\x1b[47m\x1b[31m<\x1b[30m>\x1b[33m<\x1b[0m", + Colors: &Colors{Foreground: "black", Background: "white"}, + }, } for _, tc := range cases {