Skip to content
Browse files

bugfix: handle reqex subdomains that match empty

  • Loading branch information...
1 parent bfc53f1 commit ca933b372a38d19b5b830f3789f560ac84950cf9 @matthewrobertson committed Feb 4, 2013
Showing with 16 additions and 3 deletions.
  1. +8 −2 lib/ress/subdomain.rb
  2. +1 −1 lib/ress/version.rb
  3. +7 −0 spec/ress/subdomain_spec.rb
View
10 lib/ress/subdomain.rb
@@ -62,10 +62,16 @@ def matches?(subdomain)
end
def url(protocol, fullpath, subdomain)
- fullpath = fullpath[(subdomain.length + 1)..-1]
+
+ fullpath = fullpath[(subdomain.length + 1)..-1] unless subdomain.empty?
begin
if matches?(subdomain)
- return "#{protocol}#{subdomain}.#{fullpath}"
+ if subdomain.empty?
+ return "#{protocol}#{fullpath}"
+ else
+ return "#{protocol}#{subdomain}.#{fullpath}"
+ end
+
end
subdomain = subdomain.split('.')[1..-1].join('.')
end while(!subdomain.empty?)
View
2 lib/ress/version.rb
@@ -1,3 +1,3 @@
module Ress
- VERSION = "0.0.7"
+ VERSION = "0.0.8"
end
View
7 spec/ress/subdomain_spec.rb
@@ -107,6 +107,13 @@
'http://foo.bar.com/some/stuff'
end
+ it 'can handle empty subdomains' do
+ 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'
+ end
+
end
end
end

0 comments on commit ca933b3

Please sign in to comment.
Something went wrong with that request. Please try again.