From 60c66b5e087706b58aa5ff7072732c8ab8b8e7c1 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Wed, 6 Feb 2013 17:40:34 -0800 Subject: [PATCH] Fix a bug where host matching occurs out of order * Closes #504 --- lib/rack/urlmap.rb | 3 ++- test/spec_urlmap.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rack/urlmap.rb b/lib/rack/urlmap.rb index d3b95a5cb..d301ce9bf 100644 --- a/lib/rack/urlmap.rb +++ b/lib/rack/urlmap.rb @@ -13,6 +13,7 @@ module Rack class URLMap NEGATIVE_INFINITY = -1.0 / 0.0 + INFINITY = 1.0 / 0.0 def initialize(map = {}) remap(map) @@ -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 diff --git a/test/spec_urlmap.rb b/test/spec_urlmap.rb index a2ad5d1aa..316c72544 100644 --- a/test/spec_urlmap.rb +++ b/test/spec_urlmap.rb @@ -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