jeanphix / django-resumable

django backend for resumable.js xhr uploads.
61 stars 21 forks source link

File with special filenames won't upload properly #15

Closed rphlo closed 1 year ago

rphlo commented 4 years ago

I tried to upload file with name foo[bar].mov and it won't upload renaming it to foobar.mov works. I have isolated the error to this piece of code in files.py

    def chunk_names(self):
        """Iterates over all stored chunks and yields their names."""
        file_names = sorted(self.storage.listdir('')[1])
        pattern = '%s%s*' % (self.filename, self.chunk_suffix)
        for name in file_names:
            if fnmatch.fnmatch(name, pattern):
                yield name

using fnname.fnmatch on the pattern of the filename itself cause issue as brackets are not escaped.

My work around is to replace chunk_names method with

    def chunk_names(self):
        """Iterates over all stored chunks and yields their names."""
        file_names = sorted(self.storage.listdir('')[1])
        pattern = '%s%s' % (self.filename, self.chunk_suffix)
        for name in file_names:
            if name[:-4] == pattern:
                yield name