fix being incorrectly escaped

This commit is contained in:
A_D 2019-04-05 07:53:13 +02:00
parent ca74bf6a17
commit 78216e0013
No known key found for this signature in database
GPG Key ID: C242F3DD220FA945
2 changed files with 23 additions and 2 deletions

@ -171,8 +171,16 @@ func Escape(in string) string {
out.WriteRune(']')
} else {
out.WriteRune(inRunes[0])
inRunes = inRunes[1:]
// special case for $$c
if len(inRunes) > 2 && inRunes[0] == '$' && inRunes[1] == '$' && inRunes[2] == 'c' {
out.WriteRune(inRunes[0])
out.WriteRune(inRunes[1])
out.WriteRune(inRunes[2])
inRunes = inRunes[3:]
} else {
out.WriteRune(inRunes[0])
inRunes = inRunes[1:]
}
}
}

@ -14,6 +14,9 @@ var tests = []testcase{
{"te$c[green]4st", "te\x03034st"},
{"te$c[red,green]9st", "te\x034,039st"},
{" ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪", " ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪"},
{"test $$c", "test $c"},
{"test $c[]", "test \x03"},
{"test $$", "test $"},
}
var escapetests = []testcase{
@ -61,6 +64,16 @@ func TestEscape(t *testing.T) {
}
}
func TestChain(t *testing.T) {
for _, pair := range tests {
escaped := Escape(pair.unescaped)
unescaped := Unescape(escaped)
if unescaped != pair.unescaped {
t.Errorf("for %q expected %q got %q", pair.unescaped, pair.unescaped, unescaped)
}
}
}
func TestUnescape(t *testing.T) {
for _, pair := range tests {
val := Unescape(pair.escaped)