mbleigh / subdomain-fu

A new plugin approach to attempting to solve the usage of subdomains in linking and routing in Rails projects.
http://rdoc.info/projects/mbleigh/subdomain-fu
Other
586 stars 118 forks source link

Crash when requesting URL with tld_size different than expected #11

Open s01ipsist opened 14 years ago

s01ipsist commented 14 years ago

With a tld_size=1, requesting a url with the host 'localhost' will crash rails url_helpers. This is probably an edge case but was unavoidable for me as Monit (old version) would only use 'localhost' as a host so this made monit monitoring impossible.

The offending code

def self.host_without_subdomain(host) parts = host.split('.') parts[-(SubdomainFu.tld_size+1)..-1].join(".") end

could be replaced with

def self.host_without_subdomain(host) parts = host.split('.') host_without_sub = parts[-(SubdomainFu.tld_size+1)..-1] host_without_sub.blank? ? host : host_without_sub.join(".") end

danielmorrison commented 14 years ago

I'm playing with the best way to fix this and will submit a patch soon.

danielmorrison commented 14 years ago

I patched it in a fork: http://github.com/collectiveidea/subdomain-fu/commit/9eb8b18d98dd5c28b9bc72f96e2dc95ccb85984

Would love to see it merged in.