shizmob / pydle

An IRCv3-compliant Python 3 IRC library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Escape characters are not properly decoded in tags

jacobmartin0 opened this issue · comments

I've been using this library to write a program that records Twitch chat for later playback. Pydle has been a big help, but I ran into a problem. It seems like the escape characters for IRCv3 tags (described here) are improperly interpreted. Rather than taking on the character they represent, they are given an extra backslash, so \s becomes \\s.

For example, if a message like the following is sent,

@extradata=This\sis\sescaped :test.example.com PRIVMSG #channel :some message

the value of message.tags['extradata'] is This\\sis\\sescaped when I would have expected This is escaped.

I can work around this by replacing \\ + an escape character with the appropriate character, but it would be nice if this wasn't necessary.

Hm, are you sure this isn't just python's escape sequences? \ is used as the escape sequence character in python's strings, so if a \ occurs within a string and isn't an escape sequence its stored escaped as \\, which shouldn't effect parsing.

Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: data = r"@extradata=This\sis\sescaped :test.example.com PRIVMSG #channel
   ...:  :some message"                                                         

In [2]: data                                                                    
Out[2]: '@extradata=This\\sis\\sescaped :test.example.com PRIVMSG #channel :some message'

In [3]: print(data)                                                             
@extradata=This\sis\sescaped :test.example.com PRIVMSG #channel :some message

commented

ahh, \s should become a , yep this will require some additional logic added to IRCv3 message handling

Hm, are you sure this isn't just python's escape sequences? \ is used as the escape sequence character in python's strings, so if a \ occurs within a string and isn't an escape sequence its stored escaped as \\, which shouldn't effect parsing.

Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: data = r"@extradata=This\sis\sescaped :test.example.com PRIVMSG #channel
   ...:  :some message"                                                         

In [2]: data                                                                    
Out[2]: '@extradata=This\\sis\\sescaped :test.example.com PRIVMSG #channel :some message'

In [3]: print(data)                                                             
@extradata=This\sis\sescaped :test.example.com PRIVMSG #channel :some message

You're correct! I wasn't familiar with how Python handled that.

Also, thank you both for considering additional support for this.