Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

CachedFilesMixin url_converter creates url for incorrect file #34

Open
antonlitvinenko opened this issue Jun 1, 2012 · 1 comment
Open

Comments

@antonlitvinenko
Copy link

I think CachedFilesMixin has a bug somewhere around lines (storage.py lines 200-213)

            url_parts = url.split('/')
            parent_level, sub_level = url.count('..'), url.count('/')
            if url.startswith('/'):
                sub_level -= 1
                url_parts = url_parts[1:]
            if parent_level or not url.startswith('/'):
                start, end = parent_level + 1, parent_level
            else:
                if sub_level:
                    if sub_level == 1:
                        parent_level -= 1
                    start, end = parent_level, sub_level - 1
                else:
                    start, end = 1, sub_level - 1
            joined_result = '/'.join(name_parts[:-start] + url_parts[end:])

In my case I enter this block with: name_parts = [u'css', u'plugins', u'toaster.css'] and url = '/assets/images/icons/fancy_close.png' and expect joined_result in the end be images/icons/fancy_close.png, but instead it is icons/fancy_close.png.

For a url='/assets/images/glyphicons-halflings.png' it seems to work correct.

@antonlitvinenko
Copy link
Author

I was able to overcome this by monkey-patching and changing to

            if parent_level or not url.startswith('/'):
                start, end = parent_level + 1, parent_level
            else:
                if sub_level:
                    if sub_level == 1:
                        parent_level -= 1
                    start, end = parent_level, 1 # <---- USING '1' HERE INSTEAD OF 'sub_level - 1'
                else:
                    start, end = 1, sub_level - 1

It works in my env, though I am not sure if this is correct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant