Permalink
Browse files

Do not mutate options given to TryStatic.new

Otherwise, given the following rackup file

----8<----clip----8<----
require 'rack'
require 'rack/contrib/try_static'

use Rack::ShowExceptions

map '/foo' do
  use Rack::TryStatic, :root => File.expand_path('public', File.dirname(__FILE__)), :urls => %w{/}, :try => %w{.html index.html /index.html}
end

run proc { [200, {'Content-Type' => 'text/html', 'Content-Length' => '3'}, ["404"]] }
----8<----clip----8<----

and the following sequence of requests against running it with
`rackup`:

1. GET /foo
2. GET /bar
3. GET /foo

Causes the options to be different in step 3 than in step 1. There
will be no :try option in step 3.
  • Loading branch information...
1 parent d127328 commit 1c13e9ed73d8e0a3d685e78972a1283f149e4d5a @tkareine tkareine committed Apr 4, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/rack/contrib/try_static.rb
  2. +10 −0 test/spec_rack_try_static.rb
@@ -17,7 +17,7 @@ class TryStatic
def initialize(app, options)
@app = app
- @try = ['', *options.delete(:try)]
+ @try = ['', *options[:try]]
@static = ::Rack::Static.new(
lambda { |_| [404, {}, []] },
options)
@@ -43,4 +43,14 @@ def request(options = {})
res.body.strip.should == "existing.html"
end
end
+
+ context 'when sharing options' do
+ it 'should not mutate given options' do
+ org_options = build_options :try => ['/index.html']
+ given_options = org_options.dup
+ request(given_options).get('/documents').should.be.ok
+ request(given_options).get('/documents').should.be.ok
+ given_options.should == org_options
+ end
+ end
end

0 comments on commit 1c13e9e

Please sign in to comment.