Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash in uri helper on Integer input #1890

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def redirect(uri, *args)
# Generates the absolute URI for a given path in the app.
# Takes Rack routers and reverse proxies into account.
def uri(addr = nil, absolute = true, add_script_name = true)
return addr if addr =~ /\A[a-z][a-z0-9+.\-]*:/i
return addr if addr.to_s =~ /\A[a-z][a-z0-9+.\-]*:/i

uri = [host = String.new]
if absolute
Expand Down
6 changes: 6 additions & 0 deletions test/helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,12 @@ def obj.is_a?(thing) 60.is_a?(thing) end
assert_equal 'http://example.org/foo/bar', body
end

it 'handles integer input' do
mock_app { get('/') { uri 123 }}
get '/'
assert_equal 'http://example.org/123', body
end

it 'handles absolute URIs' do
mock_app { get('/') { uri 'http://google.com' }}
get '/'
Expand Down