Skip to content

Commit

Permalink
Handle invalid URIs. Closes #78
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Matthies committed Apr 13, 2015
1 parent 31d5005 commit 6e94dec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/ssl-enforcer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def modify_location_and_redirect
location = replace_scheme(location, @scheme)
location = replace_host(location, @options[:redirect_to])
redirect_to(location)
rescue URI::InvalidURIError
[400, { 'Content-Type' => 'text/plain'}, []]
end

def redirect_to(location)
Expand Down
8 changes: 8 additions & 0 deletions test/rack-ssl-enforcer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1061,4 +1061,12 @@ def self.startup
assert_equal last_response.body, '<html><body>Hello!</body></html>'
end
end

context 'invalid urls' do
should 'return HTTP 400 for invalid URIs' do
response = Rack::SslEnforcer.new(nil).call('PATH_INFO' => 'http://www.example.org/<lan')
status_code = response.first
assert_equal status_code, 400
end
end
end

0 comments on commit 6e94dec

Please sign in to comment.