From ba25ade98fd34c873429e7a7dfa52df739962e4d Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sun, 24 May 2020 15:43:56 +0200 Subject: [PATCH] SPEC: Require "status" to be Integer and >= 100 - #1644 refers to the idea "require Status to be an Integer" - This implements that change --- CHANGELOG.md | 1 + SPEC.rdoc | 4 ++-- lib/rack/lint.rb | 8 +++++--- test/spec_content_type.rb | 8 -------- test/spec_lint.rb | 11 +++++++++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d0701ee..839b315ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. For info on ### Changed +- BREAKING CHANGE: Require `status` to be an Integer. ([#1662](https://github.com/rack/rack/pull/1662), [@olleolleolle](https://github.com/olleolleolle)) - Relax validations around `Rack::Request#host` and `Rack::Request#hostname`. ([#1606](https://github.com/rack/rack/issues/1606), [@pvande](https://github.com/pvande)) - Removed antiquated handlers: FCGI, LSWS, SCGI, Thin. ([#1658](https://github.com/rack/rack/pull/1658), [@ioquatix](https://github.com/ioquatix)) diff --git a/SPEC.rdoc b/SPEC.rdoc index 6c6b95b8a..4cb02d744 100644 --- a/SPEC.rdoc +++ b/SPEC.rdoc @@ -246,8 +246,8 @@ if the request env has rack.hijack? true. request pattern is intended to provide the hijacker with "raw tcp". == The Response === The Status -This is an HTTP status. When parsed as integer (+to_i+), it must be -greater than or equal to 100. +This is an HTTP status. It must be an Integer greater than or equal to +100. === The Headers The header must respond to +each+, and yield values of key and value. The header keys must be Strings. diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb index 67493af45..67264771d 100755 --- a/lib/rack/lint.rb +++ b/lib/rack/lint.rb @@ -659,9 +659,11 @@ def check_hijack_response(headers, env) ## === The Status def check_status(status) - ## This is an HTTP status. When parsed as integer (+to_i+), it must be - ## greater than or equal to 100. - assert("Status must be >=100 seen as integer") { status.to_i >= 100 } + ## This is an HTTP status. It must be an Integer greater than or equal to + ## 100. + assert("Status must be an Integer >=100") { + status.is_a?(Integer) && status >= 100 + } end ## === The Headers diff --git a/test/spec_content_type.rb b/test/spec_content_type.rb index 4cfc32231..a11d2c9d3 100644 --- a/test/spec_content_type.rb +++ b/test/spec_content_type.rb @@ -44,12 +44,4 @@ def request response[1]['Content-Type'].must_be_nil end end - - ['100', '204', '304'].each do |code| - it "not set Content-Type on #{code} responses if status is a string" do - app = lambda { |env| [code, {}, []] } - response = content_type(app, "text/html").call(request) - response[1]['Content-Type'].must_be_nil - end - end end diff --git a/test/spec_lint.rb b/test/spec_lint.rb index f7da81c33..3847116b1 100755 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -266,14 +266,21 @@ def result.name ["cc", {}, ""] }).call(env({})) }.must_raise(Rack::Lint::LintError). - message.must_match(/must be >=100 seen as integer/) + message.must_match(/must be an Integer >=100/) lambda { Rack::Lint.new(lambda { |env| [42, {}, ""] }).call(env({})) }.must_raise(Rack::Lint::LintError). - message.must_match(/must be >=100 seen as integer/) + message.must_match(/must be an Integer >=100/) + + lambda { + Rack::Lint.new(lambda { |env| + ["200", {}, ""] + }).call(env({})) + }.must_raise(Rack::Lint::LintError). + message.must_match(/must be an Integer >=100/) end it "notice header errors" do