ircmsg: Make ircmsg respect emoji in tags

This commit is contained in:
Daniel Oaks 2018-02-11 01:12:16 +10:00
parent 55652e4096
commit 1cb16094f0
2 changed files with 7 additions and 5 deletions

@ -10,7 +10,7 @@ var (
valtoescape = strings.NewReplacer("\\", "\\\\", ";", "\\:", " ", "\\s", "\r", "\\r", "\n", "\\n")
// escapetoval contains the IRCv3 Tag Escapes and how they map to characters.
escapetoval = map[byte]byte{
escapetoval = map[rune]byte{
':': ';',
's': ' ',
'\\': '\\',
@ -31,10 +31,10 @@ func EscapeTagValue(in string) string {
//
// This function is automatically used when lines are interpreted by ParseLine,
// so you don't need to call it yourself after parsing a line.
func UnescapeTagValue(in string) string {
out := ""
for len(in) > 0 {
func UnescapeTagValue(inString string) string {
in := []rune(inString)
var out string
for 0 < len(in) {
if in[0] == '\\' && len(in) > 1 {
val, exists := escapetoval[in[1]]
if exists == true {

@ -13,12 +13,14 @@ type testcase struct {
var tests = []testcase{
{"te\\nst", "te\nst"},
{"tes\\\\st", "tes\\st"},
{"te😃st", "te😃st"},
}
var unescapeTests = []testcase{
{"te\\n\\kst", "te\nkst"},
{"te\\n\\kst\\", "te\nkst"},
{"te\\\\nst", "te\\nst"},
{"te😃st", "te😃st"},
}
func TestEscape(t *testing.T) {