Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

CachedFilesMixin url_converter creates url for incorrect file #34

Open
antonlitvinenko opened this Issue · 1 comment

1 participant

@antonlitvinenko

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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.