diff --git a/lib/rack/cors.rb b/lib/rack/cors.rb index 0a23106..131368a 100644 --- a/lib/rack/cors.rb +++ b/lib/rack/cors.rb @@ -278,8 +278,8 @@ def origins(*args, &blk) case n when Proc, Regexp, - /^https?:\/\//, 'file://' then n + when /^https?:\/\// then URI.parse(n).to_s when '*' then @public_resources = true; n else Regexp.compile("^[a-z][a-z0-9.+-]*:\\\/\\\/#{Regexp.quote(n)}$") end diff --git a/test/unit/cors_test.rb b/test/unit/cors_test.rb index f79c9fb..2e8987d 100644 --- a/test/unit/cors_test.rb +++ b/test/unit/cors_test.rb @@ -270,6 +270,13 @@ def load_app(name) cors_result.must_be :preflight end + it 'should allow HTTP/HTTPS origin without the default port' do + preflight_request('http://allow-the-default-port.io', '/') + last_response.must_render_cors_success + preflight_request('https://allow-the-default-port.io', '/') + last_response.must_render_cors_success + end + it 'should allow any header if headers = :any' do preflight_request('http://localhost:3000', '/', :headers => 'Fooey') last_response.must_render_cors_success diff --git a/test/unit/test.ru b/test/unit/test.ru index 5793de1..55b9377 100644 --- a/test/unit/test.ru +++ b/test/unit/test.ru @@ -8,7 +8,9 @@ use Rack::Cors do '127.0.0.1:3000', /http:\/\/192\.168\.0\.\d{1,3}(:\d+)?/, 'file://', - /http:\/\/(.*?)\.example\.com/ + /http:\/\/(.*?)\.example\.com/, + 'http://allow-the-default-port.io:80', + 'https://allow-the-default-port.io:443' resource '/get-only', :methods => :get resource '/', :headers => :any, :methods => :any