Skip to content

Commit

Permalink
Make url arg act more like Rack::Static (aka. urls). It can take a si…
Browse files Browse the repository at this point in the history
…ngle string
  • Loading branch information
Brian Mitchell committed Jan 28, 2010
1 parent a02f812 commit 484233f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/rack/coffee.rb
Expand Up @@ -4,22 +4,22 @@

class Rack::Coffee

attr_accessor :url, :root
attr_accessor :urls, :root

DEFAULTS = {:static => true}

def initialize(app, opts = {})
opts = DEFAULTS.merge(opts)
@app = app
@url = opts[:url] || '/javascripts'
@urls = *opts[:urls] || '/javascripts'
@root = opts[:root] || Dir.pwd
@server = opts[:static] ? Rack::File.new(root) : app
end

def call(env)
path = Rack::Utils.unescape(env["PATH_INFO"])
return [403, {"Content-Type" => "text/plain"}, ["Forbidden\n"]] if path.include?('..')
return @app.call(env) unless path.index(url) == 0 && path =~ /\.js$/
return @app.call(env) unless urls.any? {|url| path.index(url) == 0} && path =~ /\.js$/
coffee = File.join(root, path.sub(/\.js$/, '.coffee'))
if File.file?(coffee)
headers = {
Expand Down
2 changes: 1 addition & 1 deletion test/rack_coffee_test.rb
Expand Up @@ -53,7 +53,7 @@ def test_does_not_allow_directory_travesal_with_encoded_periods
end

def test_serves_coffeescripts_with_alternate_options
result = request({:root => File.expand_path(File.dirname(__FILE__)), :url => "/other_javascripts"}).get("/other_javascripts/test.js")
result = request({:root => File.expand_path(File.dirname(__FILE__)), :urls => "/other_javascripts"}).get("/other_javascripts/test.js")
assert_equal 200, result.status
assert_match /alert\(\"other coffee\"\)\;/, result.body
end
Expand Down

0 comments on commit 484233f

Please sign in to comment.