Do not mutate options in TryStatic.new #53

Merged
merged 3 commits into from Dec 10, 2012

Conversation

Projects
None yet
5 participants
Contributor

tkareine commented Apr 4, 2012

If I have a following rackup file:

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"]] }

And I run it with rackup, issuing the following requests:

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

In step 1, TryStatic.new modifies the options, but returns the static file correctly. In step 3, the same options instance gets passed to TryStatic.new. Then, there is no :try key left, because it was removed in step 1. This causes the static file not be returned.

This patch changes TryStatic#initialize so that it does not change the options given to it.

Also, commit 04ced70 of the patch is possibly related to GH-48.

tkareine added some commits Apr 4, 2012

@tkareine tkareine Add unused env parameter for lambdas (Ruby 1.9 compatibility)
Possibly related to GH-48
#48
04ced70
@tkareine tkareine Explicitly build options for tests, will be needed next d127328
@tkareine tkareine 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.
1c13e9e

lgierth commented Apr 4, 2012

Arguments shouldn't be modified, good catch!

Contributor

tkareine commented May 28, 2012

maintainer ping

maccman commented Jun 4, 2012

Ping @tomayko

@rtomayko TryStatic is broken (at least in 1.9) and this pull request fixes it.

jpmckinney referenced this pull request Aug 30, 2012

Closed

TryStatic #48

@rkh rkh added a commit that referenced this pull request Dec 10, 2012

@rkh rkh Merge pull request #53 from tkareine/do_not_mutate_options_in_try_static
Do not mutate options in TryStatic.new
84a4bdf

@rkh rkh merged commit 84a4bdf into rack:master Dec 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment