Skip to content

Fix engine named routes regression#21743

Closed
merhard wants to merge 2 commits intorails:4-2-stablefrom
merhard:engine_route_helper_fix
Closed

Fix engine named routes regression#21743
merhard wants to merge 2 commits intorails:4-2-stablefrom
merhard:engine_route_helper_fix

Conversation

@merhard
Copy link
Copy Markdown
Contributor

@merhard merhard commented Sep 23, 2015

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:

  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 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 using the value of default_url_options[:script_name] or an empty string as a benign truthy value for options[:script_name] when the prefix is being generated, avoiding the duplicate relative_url_root value in the final result.

This resolves issues #20920 and #21459.
This is an alternative pull request to #20958.

Matthew Erhard added 2 commits September 23, 2015 18:21
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.
@rails-bot
Copy link
Copy Markdown

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.

@rails-bot
Copy link
Copy Markdown

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 4-2-stable. Please double check that you specified the right target!

@arthurnn
Copy link
Copy Markdown
Member

#18775 was merged into master, is this a problem there too?

@merhard
Copy link
Copy Markdown
Contributor Author

merhard commented Sep 28, 2015

@arthurnn
Good call. It is a problem there as well. Verified against the testapp and the test in this pull request.

I was so focused on the v4.2 regression I forgot to check on master. Should I open a new pull request against master?

@rafaelfranca
Copy link
Copy Markdown
Member

Should I open a new pull request against master?

Yes please. And we will backport the fix to 4-2-stable if we think it is applicable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants