Fix engine named routes regression#21743
Conversation
When generating the url for a mounted engine through its proxy, the path should be the sum of three parts: 1. Any `SCRIPT_NAME` request header or the value of `relative_url_root`. 2. A prefix (the engine's mounted path). 3. The path of the named route inside the engine. Since commit rails@0703453, this has been broken. Instead, the path is the sum of four parts: 1. Any `SCRIPT_NAME` request header or the value of `relative_url_root`. 2. The value of `relative_url_root`. 3. A prefix (the engine's mounted path). 4. The path of the named route inside the engine. This commit fixes the regression by providing a benign truthy value for `options[:script_name]` (an empty string) when the prefix is being generated, avoiding the duplicate `relative_url_root` value in the final result. This resolves rails#20920, resolves rails#21459, and closes rails#20958
Fixes two test failures having to do with respecting `default_url_options`: 1. TestGenerationPrefix::WithMountedEngine#test_[APP]_generating_engine's_route_includes_default_url_options[:script_name] [/Users/merhard/Documents/personal/rails/actionpack/test/dispatch/prefix_generation_test.rb:243] 2. TestGenerationPrefix::WithMountedEngine#test_[OBJECT]_generating_engine's_route_includes_default_url_options[:script_name] [/Users/merhard/Documents/personal/rails/actionpack/test/dispatch/prefix_generation_test.rb:281] The empty string was overriding the potential `default_url_options[:script_name]` value. This is fixed by defaulting to `default_url_options` and falling back to an empty string if missing.
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @arthurnn (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
#18775 was merged into master, is this a problem there too? |
Yes please. And we will backport the fix to 4-2-stable if we think it is applicable |
This pull request aims to fix a regression that has been present in Rails since v4.2.2
When generating the url for a mounted engine through its proxy, the path should be the sum of three parts:
SCRIPT_NAMErequest header or the value ofrelative_url_root.Since commit 0703453, this has been broken. Instead, the path is the sum of four parts:
SCRIPT_NAMErequest header or the value ofrelative_url_root.relative_url_root.This commit fixes the regression by using the value of
default_url_options[:script_name]or an empty string as a benign truthy value foroptions[:script_name]when the prefix is being generated, avoiding the duplicaterelative_url_rootvalue in the final result.This resolves issues #20920 and #21459.
This is an alternative pull request to #20958.