Skip to content

Commit

Permalink
Fix a bug where host matching occurs out of order
Browse files Browse the repository at this point in the history
 * Closes #504
  • Loading branch information
raggi committed Feb 7, 2013
1 parent e6b70a7 commit 60c66b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rack/urlmap.rb
Expand Up @@ -13,6 +13,7 @@ module Rack

class URLMap
NEGATIVE_INFINITY = -1.0 / 0.0
INFINITY = 1.0 / 0.0

def initialize(map = {})
remap(map)
Expand All @@ -35,7 +36,7 @@ def remap(map)

[host, location, match, app]
}.sort_by do |(host, location, _, _)|
[host ? -host.size : NEGATIVE_INFINITY, -location.size]
[host ? -host.size : INFINITY, -location.size]
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/spec_urlmap.rb
Expand Up @@ -110,7 +110,7 @@

res = Rack::MockRequest.new(map).get("http://foo.org/")
res.should.be.ok
res["X-Position"].should.equal "default.org"
res["X-Position"].should.equal "foo.org"

res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "example.org")
res.should.be.ok
Expand Down

0 comments on commit 60c66b5

Please sign in to comment.