You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When routing a request, #find_routes will iterate through potential routes for the request and yield them to the passed block. #serve and #recognize both used #find_routes, but ended up handling things slightly differently. Both methods would modify the script_name and path_info of the request if the current route is not anchored. However, only #serve used #chomp and would restore the request's original script_name and path_info after each iteration. This inconsistency can cause issues as #recognize can end up not matching them even though #serve would.
Detail
This commit fixes the issue by unifying more of the implementations of #serve and #recognize. Now, #find_routes implements the mutation/restoration of request params for both #serve and #recognize so that their behavior is consistent and request mutation isn't leaked between iterations.
One test had to be changed because it depended on the request mutation leaking outside of #recognize, so it was updated to make assertions during #recognize instead.
Additional information
Fixes #31152
Checklist
Before submitting the PR make sure the following are checked:
This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
Tests are added or updated if you fix a bug or add a feature.
CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
Motivation / Background
When routing a request,
#find_routes
will iterate through potential routes for the request and yield them to the passed block.#serve
and#recognize
both used#find_routes
, but ended up handling things slightly differently. Both methods would modify thescript_name
andpath_info
of the request if the current route is not anchored. However, only#serve
used#chomp
and would restore the request's originalscript_name
andpath_info
after each iteration. This inconsistency can cause issues as#recognize
can end up not matching them even though#serve
would.Detail
This commit fixes the issue by unifying more of the implementations of
#serve
and#recognize
. Now,#find_routes
implements the mutation/restoration of request params for both#serve
and#recognize
so that their behavior is consistent and request mutation isn't leaked between iterations.One test had to be changed because it depended on the request mutation leaking outside of
#recognize
, so it was updated to make assertions during#recognize
instead.Additional information
Fixes #31152
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
Originally posted by @skipkayhil in rails/rails#54550
The text was updated successfully, but these errors were encountered: