From a6e9cac8eb6106e6b33857a5c4ffd6a0f0c6fa79 Mon Sep 17 00:00:00 2001 From: Joslyn Esser Date: Wed, 12 Oct 2011 10:37:25 -0700 Subject: [PATCH] Fixing url_rewriter when there is no host available (example: including url_helpers in a model where a @request object is not available) --- lib/subdomain_fu/subdomain_fu.rb | 2 +- spec/subdomain_fu_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/subdomain_fu/subdomain_fu.rb b/lib/subdomain_fu/subdomain_fu.rb index 7458927..a251069 100644 --- a/lib/subdomain_fu/subdomain_fu.rb +++ b/lib/subdomain_fu/subdomain_fu.rb @@ -131,7 +131,7 @@ def self.override_only_path? end def self.needs_rewrite?(subdomain, host) - return false if host.count('.') < config.tld_size + return false unless host && host.count('.') >= config.tld_size case subdomain when nil #rewrite when there is a preferred mirror set and there is no subdomain on the host diff --git a/spec/subdomain_fu_spec.rb b/spec/subdomain_fu_spec.rb index a027b50..cb7e189 100644 --- a/spec/subdomain_fu_spec.rb +++ b/spec/subdomain_fu_spec.rb @@ -258,6 +258,7 @@ it { SubdomainFu.needs_rewrite?(false,"awesome.localhost").should be_true } it { SubdomainFu.needs_rewrite?(false,"www.localhost").should be_false } it { SubdomainFu.needs_rewrite?("www","awesome.localhost").should be_true } + it { SubdomainFu.needs_rewrite?(nil, nil).should be_false } describe "when preferred_mirror is false" do before do