Skip to content

Commit

Permalink
Avoid crash in uri helper on Integer input (#1890)
Browse files Browse the repository at this point in the history
Ruby 3.2.0 removed Object#=~ in ruby/ruby#5383

Has been deprecated since Ruby 2.6.0:
ruby/ruby@ebff9dc
https://bugs.ruby-lang.org/issues/15231
  • Loading branch information
dentarg authored Feb 26, 2023
1 parent 50b8398 commit 892cbeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 892cbeb

Please sign in to comment.