jaraco / irc

Full-featured Python IRC library for Python.
MIT License
392 stars 86 forks source link

dccsend.py and dccreceive.py can't parse filenames with space character correctly. #49

Closed jaraco closed 8 years ago

jaraco commented 8 years ago

Maybe you can use another split character:

#!python

#dccsend.py
def on_welcome(self, connection, event):
        self.dcc = self.dcc_listen("raw")
        self.connection.ctcp("DCC", self.receiver, "SEND:%s:%s:%d:%d" % (
            os.path.basename(self.filename),
            irc.client.ip_quad_to_numstr(self.dcc.localaddress),
            self.dcc.localport,
            self.filesize))
#!python
#dccreceive.py

def on_ctcp(self, connection, event):
        args = event.arguments[1].split(':')

jaraco commented 8 years ago

hmm. I wonder what is the correct syntax. Presumably, we can make dccsend and dccreceive work together, but I'd like also for them to work with other tools. Do you know what syntax other tools use for sending or receiving files with spaces? Is there perhaps a spec for it?


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

I don't know if there is a spec but i think shlex module will be nice for splitting.

#!python

>>> import shlex
>>> shlex.split('something "D:\\filename with space" -c')
['something', 'D:\\filename with space', '-c']

Original comment by: Carabelli

jaraco commented 8 years ago

I agree that form is nicer for capturing file names with spaces, but it still doesn't help align the library with the protocol. One way you could test is to set up dccreceive.py to receive a file, but then use a publically-available IRC client to send a file, and see what content dccreceive gets.

I suspect there will need to be some escaping and unescaping, but it's not obvious to me without more investigation what that would be.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

I ran a test with HexChat as the sender, and I found that the incoming "args" were: ['SEND', '"Introducing', 'ASP.NET', 'vNext', '-', 'Scott', 'Hanselman.URL"', '3232235778', '56038', '240']. So it seems that at least one client uses quotes around a filename with spaces. In that case, using shlex should do the trick.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

Use list2cmdline and shlex to handle spaces in DCC files. Fixes #49.

→ <<cset 9e4fb0ce9223>>


Original comment by: Jason R. Coombs