Skip to content

Commit

Permalink
Merge pull request #16168 from greysteil/stash-path-info
Browse files Browse the repository at this point in the history
Stash original path in `ShowExceptions` middleware
  • Loading branch information
matthewd committed Jul 14, 2014
2 parents 55c1b1d + f49d20e commit 7b52a26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion actionpack/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,19 @@
* Preserve original path in `ShowExceptions` middleware by stashing it as
`env["action_dispatch.original_path"]`

`ActionDispatch::ShowExceptions` overwrites `PATH_INFO` with the status code
for the exception defined in `ExceptionWrapper`, so the path
the user was visiting when an exception occurred was not previously
available to any custom exceptions_app. The original `PATH_INFO` is now
stashed in `env["action_dispatch.original_path"]`.

*Grey Baker*

* Use `String#bytesize` instead of `String#size` when checking for cookie * Use `String#bytesize` instead of `String#size` when checking for cookie
overflow. overflow.


*Agis Anastasopoulos* *Agis Anastasopoulos*

* `render nothing: true` or rendering a `nil` body no longer add a single * `render nothing: true` or rendering a `nil` body no longer add a single
space to the response body. space to the response body.


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def render_exception(env, exception)
wrapper = ExceptionWrapper.new(env, exception) wrapper = ExceptionWrapper.new(env, exception)
status = wrapper.status_code status = wrapper.status_code
env["action_dispatch.exception"] = wrapper.exception env["action_dispatch.exception"] = wrapper.exception
env["action_dispatch.original_path"] = env["PATH_INFO"]
env["PATH_INFO"] = "/#{status}" env["PATH_INFO"] = "/#{status}"
response = @exceptions_app.call(env) response = @exceptions_app.call(env)
response[1]['X-Cascade'] == 'pass' ? pass_response(status) : response response[1]['X-Cascade'] == 'pass' ? pass_response(status) : response
Expand Down
3 changes: 2 additions & 1 deletion actionpack/test/dispatch/show_exceptions_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def call(env)
get "/", {}, {'action_dispatch.show_exceptions' => true} get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500 assert_response 500
assert_equal "500 error fixture\n", body assert_equal "500 error fixture\n", body

get "/bad_params", {}, {'action_dispatch.show_exceptions' => true} get "/bad_params", {}, {'action_dispatch.show_exceptions' => true}
assert_response 400 assert_response 400
assert_equal "400 error fixture\n", body assert_equal "400 error fixture\n", body
Expand Down Expand Up @@ -92,6 +92,7 @@ def call(env)
exceptions_app = lambda do |env| exceptions_app = lambda do |env|
assert_kind_of AbstractController::ActionNotFound, env["action_dispatch.exception"] assert_kind_of AbstractController::ActionNotFound, env["action_dispatch.exception"]
assert_equal "/404", env["PATH_INFO"] assert_equal "/404", env["PATH_INFO"]
assert_equal "/not_found_original_exception", env["action_dispatch.original_path"]
[404, { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]] [404, { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]]
end end


Expand Down

0 comments on commit 7b52a26

Please sign in to comment.