Permalink
Browse files

Adds lint checking for invalid rack keys

  • Loading branch information...
1 parent c765e7b commit 166b96b89310b1fdbce8cc0e66a3c04b6d3def81 @wycats committed with Yehuda Katz Apr 22, 2009
Showing with 14 additions and 0 deletions.
  1. +9 −0 lib/rack/lint.rb
  2. +5 −0 test/spec_rack_lint.rb
View
@@ -161,6 +161,15 @@ def check_env(env)
rack.multithread rack.multiprocess rack.run_once].each { |header|
assert("env missing required key #{header}") { env.include? header }
}
+
+ env.each do |k, v|
+ if k =~ /^rack\./
+ assert("\"#{k}\" is not a valid key in the rack namespace") do
+ %w(rack.version rack.url_scheme rack.input rack.errors rack.multithread
+ rack.multiprocess rack.run_once rack.session).any? {|valid_key| k == valid_key }
+ end
+ end
+ end
## The environment must not contain the keys
## <tt>HTTP_CONTENT_TYPE</tt> or <tt>HTTP_CONTENT_LENGTH</tt>
View
@@ -40,6 +40,11 @@ def env(*args)
}.should.raise(Rack::Lint::LintError).
message.should.match(/missing required key SERVER_NAME/)
+ lambda {
+ e = env("rack.zomg" => "hello")
+ Rack::Lint.new(nil).call(e)
+ }.should.raise(Rack::Lint::LintError).
+ message.should.match(/"rack.zomg" is not a valid key/)
lambda {
Rack::Lint.new(nil).call(env("HTTP_CONTENT_TYPE" => "text/plain"))

0 comments on commit 166b96b

Please sign in to comment.