rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
542 stars 96 forks source link

a potential bug of image_path #181

Closed dongyuwei closed 9 years ago

dongyuwei commented 10 years ago

https://github.com/rstacruz/sinatra-assetpack/blob/master/lib/sinatra/assetpack/helpers.rb#L21

def image_path(src)
        file_path = HtmlHelpers.get_file_uri(src, settings.assets)
        File.join(request.script_name, file_path)
end

if asset_hosts configured as below:

asset_hosts [
      'http://cdn-0.example.org',
      'http://cdn-1.example.org'
]

then if request.script_name is empty string, File.join(request.script_name, file_path) will return /http://cdn-0.example.org/file_path, that's unexpected url.

//cdn-0.example.org has no this problem just because File.join('','//cdn-0.example.org') return //cdn-0.example.org.

Rendez commented 10 years ago

@dongyuwei I run into the same issue with our S3-hosted image uploads. Feel free to try the fix.