Avoid crash in `uri` helper on Integer input (#1890)

Ruby 3.2.0 removed Object#=~ in https://github.com/ruby/ruby/pull/5383

Has been deprecated since Ruby 2.6.0:
ebff9dc10e
https://bugs.ruby-lang.org/issues/15231
This commit is contained in:
Patrik Ragnarsson 2023-02-26 21:45:08 +01:00 committed by GitHub
parent 50b8398dd7
commit 892cbeb378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -317,7 +317,7 @@ module Sinatra
# 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

View File

@ -1845,6 +1845,12 @@ class HelpersTest < Minitest::Test
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 '/'