summary refs log tree commit
diff options
context:
space:
mode:
authorJames Tucker <jftucker@gmail.com>2013-02-06 17:40:34 -0800
committerJames Tucker <jftucker@gmail.com>2013-02-07 18:33:03 -0800
commit3fc34cd2a8e89f7ec443f600fca1b5d0b1d523b1 (patch)
tree19a12cadf3eec2dcc679242776a7c2a880eda3ad
parent71ce52cc7a7ecbbaa7c3db98ef6455de6c0aaca2 (diff)
downloadrack-3fc34cd2a8e89f7ec443f600fca1b5d0b1d523b1.tar.gz
Fix a bug where host matching occurs out of order
 * Closes #504
-rw-r--r--lib/rack/urlmap.rb3
-rw-r--r--test/spec_urlmap.rb2
2 files changed, 3 insertions, 2 deletions
diff --git a/lib/rack/urlmap.rb b/lib/rack/urlmap.rb
index d3b95a5c..d301ce9b 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 @@ module Rack
 
         [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 a2ad5d1a..316c7254 100644
--- a/test/spec_urlmap.rb
+++ b/test/spec_urlmap.rb
@@ -110,7 +110,7 @@ describe Rack::URLMap do
 
     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