Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FailureApps script_name: nil breaks route generation within mounted engines #3705

Closed
jvdp opened this issue Aug 12, 2015 · 14 comments
Closed

Comments

@jvdp
Copy link

jvdp commented Aug 12, 2015

Since upgrading to Devise 3.5.2, the Devise::FailureApp from within a Rails engine no longer generates routes with the path it is mounted under.

The breaking change was made in aa675f7, which always passes a script_name (possibly nil) to the url generator. This is problematic because the mount point path is only computed when script_name is not passed to options: https://github.com/rails/rails/blob/v4.2.3/actionpack/lib/action_dispatch/routing/mapper.rb#L631

I'm not sure how to fix this (this is all crazy complicated code), but perhaps there's a better fix for #3643 than forcing path_name to be passed to url_for.

@josevalim
Copy link
Contributor

Which Rails version are you using?

@jvdp
Copy link
Author

jvdp commented Aug 12, 2015

Rails 4.2.3.

@josevalim
Copy link
Contributor

@jvdp so apparently if we don't set it, there is a infinite loop. If we set it, we break engines. :(

@jvdp
Copy link
Author

jvdp commented Aug 20, 2015

Yep, it sucks. Do you think this should be fixed in Rails instead?

@mmitchellg5
Copy link

We're running into this as well, with Rails 4.2.4

@variousred
Copy link

FWIW as a test I deleted this whole bit:

      # Rails 4.2 goes into an infinite loop if opts[:script_name] is unset
      if (Rails::VERSION::MAJOR >= 4) && (Rails::VERSION::MINOR >= 2)
        opts[:script_name] = (config.relative_url_root if config.respond_to?(:relative_url_root))
      else
        if config.respond_to?(:relative_url_root) && config.relative_url_root.present?
          opts[:script_name] = config.relative_url_root
        end
      end

and I did NOT get an infinite loop, everything worked.

@mmitchellg5
Copy link

@jvdp @josevalim

@jvdp
Copy link
Author

jvdp commented Sep 8, 2015

@mmitchellg5 hey if that fixes it, great, but doesn't that break a configuration option? If you can make a PR / fork I'll try it on my app.

For completeness I think #3738 is a duplicate of this (and #3739 a proposed fix, but by adding instead of removing code.)

@variousred
Copy link

@jvdp sure does, but you can just delete the conditional since apparently rails 4.2.4 does NOT go into an infinite loop without the setting.

@stanhu
Copy link
Contributor

stanhu commented Sep 10, 2015

I think #3738 may be similar but not exactly the same. I just tried disabling the setting of script_name, and it didn't solve my use case. Warden passes the entire fullpath, leaving it to the callback function to sort things out.

@kont-noor
Copy link

@variousred Also no infinite loop issue in Rails 4.2.3
UPD: also nor in any of the versions from 4.2.0 to 4.2.4

Can anything else be the reason of the bug? (Probably some another modules)

kont-noor added a commit to kont-noor/Incarnator that referenced this issue Sep 11, 2015
@cipater
Copy link

cipater commented Nov 4, 2015

@josevalim I've submitted PR #3807 that attempts to fix both #3643 and bug it caused above.

Despite suggestions to the contrary, there is definitely a infinite loop in cases where mounted engines change the SCRIPT_NAME env variable to be something other than intended path for a given scope. The '/admin/sidekiq' example in #3643 is a perfect example. I don't know enough about the internals, but it would seem something in 4.2 changed to take the SCRIPT_NAME env variable into account in the absence of a :script_name option being passed in.

@josevalim
Copy link
Contributor

Awesome, thanks ofr the PR!

vgarro added a commit to G5/devise_g5_authenticatable that referenced this issue Nov 11, 2015
- Version 3.5.2 includes a bug that causes g5_authenticatable tests to break upon login in
- heartcombo/devise#3705

[Fixes #107063598]
vgarro added a commit to G5/g5_authenticatable that referenced this issue Nov 12, 2015
vgarro added a commit to G5/devise_g5_authenticatable that referenced this issue Nov 12, 2015
- Version 3.5.2 includes a bug that causes g5_authenticatable tests to break upon login in
heartcombo/devise#3705

[Fixes #107063598]
vgarro added a commit to G5/devise_g5_authenticatable that referenced this issue Nov 12, 2015
- Version 3.5.2 includes a bug that causes g5_authenticatable tests to break upon login in
heartcombo/devise#3705

[Fixes #107063598]
vgarro added a commit to G5/devise_g5_authenticatable that referenced this issue Nov 19, 2015
- Version 3.5.2 includes a bug that causes g5_authenticatable tests to break upon login in
heartcombo/devise#3705

[Fixes #107063598]
basiszwo added a commit to basiszwo/devise that referenced this issue Apr 13, 2016
lucasmazza pushed a commit that referenced this issue May 21, 2016
Fix infinite loop in authenticated engine routes in Rails 5

#3705
@lucasmazza
Copy link
Contributor

Merged #4081 with a fix for the redirection issue - closing this for now.

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

No branches or pull requests

8 participants