Skip to content

Commit

Permalink
Allow empty PATH_INFO. (rack#2214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored and simi committed Jun 17, 2024
1 parent 6b2657f commit 4aab473
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SPEC.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ There are the following restrictions:
* There may be a valid early hints callback in <tt>rack.early_hints</tt>
* The <tt>REQUEST_METHOD</tt> must be a valid token.
* The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
* The <tt>PATH_INFO</tt>, if provided, must be a valid request target.
* The <tt>PATH_INFO</tt>, if provided, must be a valid request target or an empty string.
* Only <tt>OPTIONS</tt> requests may have <tt>PATH_INFO</tt> set to <tt>*</tt> (asterisk-form).
* Only <tt>CONNECT</tt> requests may have <tt>PATH_INFO</tt> set to an authority (authority-form). Note that in HTTP/2+, the authority-form is not a valid request target.
* <tt>CONNECT</tt> and <tt>OPTIONS</tt> requests must not have <tt>PATH_INFO</tt> set to a URI (absolute-form).
Expand Down
3 changes: 3 additions & 0 deletions config/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ roda:
grape:
url: https://github.com/ruby-grape/grape
command: bundle exec rspec --exclude-pattern=spec/integration/**/*_spec.rb
sinatra:
url: https://github.com/sinatra/sinatra
command: bundle exec rake test
4 changes: 3 additions & 1 deletion lib/rack/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def check_environment(env)
raise LintError, "SCRIPT_NAME must start with /"
end

## * The <tt>PATH_INFO</tt>, if provided, must be a valid request target.
## * The <tt>PATH_INFO</tt>, if provided, must be a valid request target or an empty string.
if env.include?(PATH_INFO)
case env[PATH_INFO]
when REQUEST_PATH_ASTERISK_FORM
Expand All @@ -381,6 +381,8 @@ def check_environment(env)
end
when REQUEST_PATH_ORIGIN_FORM
## * Otherwise, <tt>PATH_INFO</tt> must start with a <tt>/</tt> and must not include a fragment part starting with '#' (origin-form).
when ""
# Empty string is okay.
else
raise LintError, "PATH_INFO must start with a '/' and must not include a fragment part starting with '#' (origin-form)"
end
Expand Down
4 changes: 4 additions & 0 deletions test/spec_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def result.name
message.must_include('response array has 4 elements instead of 3')
end

it "accepts empty PATH_INFO" do
Rack::Lint.new(valid_app).call(env("PATH_INFO" => "")).first.must_equal 200
end

it "notices request-target asterisk form errors" do
# A non-empty PATH_INFO starting with something other than / has
# implications for Rack::Request#path and methods downstream from
Expand Down

0 comments on commit 4aab473

Please sign in to comment.