faassen/bowerstatic

usage of relative path

Closed this issue · 8 comments

Line https://github.com/faassen/bowerstatic/blob/master/bowerstatic/core.py#L239 will make that components will only work with absolute paths. Relative paths will not work. Is that by design?

Hi Marc!

The idea is that people shouldn't be allowed to escape outside of a component's directory by hiding ../../../ in their paths.

Do you have concrete use cases where this breaks bower components? I think I need some examples.

I understand your motive to do so.

I want to include bower_components in the package. The absolute directory of the package can be different on different servers. I can compute the absolute directory when creating the components, but with relative paths that won't be necessary.

Hm... it's really the bower_components directory that can be in different locations. get_file gets a path from within that, but as long as the bower_components directory is supplied differently, it won't matter.

If bower_components is within a Python package, you can use the following trick to get its directory relative to it:

os.path.join(os.path.dirname(__file__), 'bower_components')

but I can see a case where you want to specify this in configuration instead. It should still work as a relevant path to the place the process was started as I do a os.path.abspath() in there.

I see you closed the issue... did that fix your problem? Or did you give up?

At second thought, with help of your explanation, a relative path based on the process is not the right solution. It has to be the relative path of the package which created the components. I will make a helper, like (not checked for working):

def create_components(bower, name, path):
    if not os.path.isabs(path):
        file = inspect.stack()[1][1] 
        dir = os.path.split(file)[0]
        path = os.path.join(dir, path)
    return bower.components(name, path)

At third thought ;-) it can also be part of the bower.components method.

I have created a package for integrating bowerstatic with pyramid: https://github.com/mrijken/pyramid_bowerstatic

Very cool! Note that I find the code examples (especially the first) a bit tricky to read in the README.

@faassen I have a concrete example of this inability of components to reference other components causing issues. Namely, polymer. See https://github.com/Polymer/polymer/blob/0.5.x/index.html#L13 for an example of an offending line.