Permalink
Browse files

fixed a bug in regex subdomains

  • Loading branch information...
1 parent ca933b3 commit e3b8d93f25c50930da8abce1a03c021167396d6a @matthewrobertson committed Feb 5, 2013
Showing with 13 additions and 15 deletions.
  1. +0 −1 lib/ress/canonical_version.rb
  2. +10 −11 lib/ress/subdomain.rb
  3. +3 −3 spec/ress/subdomain_spec.rb
@@ -13,7 +13,6 @@ def matches?(req_subdomain)
# Create a tag of this format:
# `<link rel="canonical" href="http://www.example.com/page-1" >`
def link_tag(protocol, fullpath, req_subdomain, view)
-
view.tag :link, :rel => 'canonical', :href => url(protocol, fullpath, req_subdomain)
end
View
@@ -62,21 +62,20 @@ def matches?(subdomain)
end
def url(protocol, fullpath, subdomain)
-
fullpath = fullpath[(subdomain.length + 1)..-1] unless subdomain.empty?
+ subdomains = subdomain.split('.')
begin
- if matches?(subdomain)
- if subdomain.empty?
- return "#{protocol}#{fullpath}"
- else
- return "#{protocol}#{subdomain}.#{fullpath}"
- end
-
- end
- subdomain = subdomain.split('.')[1..-1].join('.')
- end while(!subdomain.empty?)
+ subdomain = subdomains.join('.')
+ return build_url(protocol, subdomain, fullpath) if matches?(subdomain)
+ end while(subdomains = subdomains[1..-1])
end
+ private
+
+ def build_url(protocol, subdomain, fullpath)
+ subdomain.empty? ? "#{protocol}#{fullpath}" : "#{protocol}#{subdomain}.#{fullpath}"
+ end
+
end
end
@@ -108,10 +108,10 @@
end
it 'can handle empty subdomains' do
- subdomain = Ress::Subdomain::RegexpSubdomain.new(/^(?!(m|tablet)\.).*$/)
+ subdomain = Ress::Subdomain::RegexpSubdomain.new(/^(?!(m|tablet)).*$/)
subdomain.matches?('').should be_true
- subdomain.url('http://', 'somewhere.com/some/stuff', '').should ==
- 'http://somewhere.com/some/stuff'
+ subdomain.url('http://', 'somewhere.com/some/stuff', '').should eq 'http://somewhere.com/some/stuff'
+ subdomain.url('http://', 'm.somewhere.com/some/stuff', 'm').should eq 'http://somewhere.com/some/stuff'
end
end

0 comments on commit e3b8d93

Please sign in to comment.