FileObject.__init__() a little more Windows-friendly. #132

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

FileObject.__init__() checks if platform.system() == 'Windows', and then runs a replace on '\' with '/' to make sure that the FileSubmit path argument works rather than escaping the following character.

Change to make FileObject.path Windows-friendly.
FileObject.__init__ will now check if windows, and then run a replace on
'\' with '/' to make sure that the FileSubmit path argument actually works
rather than escaping the following character.

Relates to Issue #100

thx for the patch ... did you run the filebrowser–tests before/after applying this patch? any difference?

Owner

sehmaschine commented Feb 8, 2013

@oliverseal any updates on this?

Sorry for delay. Missed your message!
There were no differences. Ran it on Windows and Linux environments.
Before patch:

Creating Test for the FileBrowser site: filebrowser
Creating test database for alias 'default'...
...................
----------------------------------------------------------------------
Ran 19 tests in 2.477s

OK
Destroying test database for alias 'default'...

After patch:

Creating Test for the FileBrowser site: filebrowser
Creating test database for alias 'default'...
...................
----------------------------------------------------------------------
Ran 19 tests in 2.171s

OK
Destroying test database for alias 'default'...
Owner

sehmaschine commented Feb 8, 2013

that´s interesting. so I guess there´s something wrong with the tests then.

Not necessarily "wrong". I'm not sure it is testing fb_versions in a way that would find this.

To explain further, line 75 of functions.py which is being called by template_tags/fb_versions.py line 56, uses this:

    return os.path.join(VERSIONS_BASEDIR, relative_path, version_filename)

Which on a Unix system the result is:

    "uploads/test-dir/test_large.png" # GOOD

But on a Windows system the result is:

    "uploads/test-dir\test_large.png" # BAD

So when templates/version.html renders and creates its FileSubmit line (line 44) in Windows it gets a path with an escaped tab in it, for example.

    "FileSubmit('uploads/test-dir\test_large.png', "

When that gets sent back from the popup window, "uploads/test-dir est_large.png" is what appears in the input field now.

In order to fix this and deal with any other places that it might be occurring, I changed it at the FileObject level so that all paths would always have the forward slash all the time always forever and ever amen.

sehmaschine added a commit that referenced this pull request Feb 14, 2013

Owner

sehmaschine commented Feb 14, 2013

fixed with stable/3.5.x

cuchac added a commit to cuchac/django-filebrowser that referenced this pull request Mar 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment