fix(ansi): return original text on [ only strings

resolves #2739
This commit is contained in:
Jan De Dobbeleer 2022-09-02 15:52:33 +02:00 committed by Jan De Dobbeleer
parent 336f351b98
commit 52f4ae662d
2 changed files with 8 additions and 2 deletions

View file

@ -144,14 +144,15 @@ func (a *Ansi) GenerateHyperlink(text string) string {
var buffer strings.Builder
var part string
for i := range parts {
part += parts[i]
if strings.Contains(parts[i], "[") && !strings.Contains(parts[i], "]") {
part += parts[i]
continue
}
part += parts[i]
buffer.WriteString(a.replaceHyperlink(part))
part = ""
}
// when we did not process any parts, we return the original text
buffer.WriteString(part)
return buffer.String()
}

View file

@ -31,6 +31,11 @@ func TestGenerateHyperlinkWithUrl(t *testing.T) {
ShellName string
Expected string
}{
{
Text: "in <accent>\x1b[1mpwsh \x1b[22m</> ",
ShellName: shell.PWSH,
Expected: "in <accent>\x1b[1mpwsh \x1b[22m</> ",
},
{
Text: "[google](http://www.google.be) [maps (2/2)](http://maps.google.be)",
ShellName: shell.FISH,