Skip to content

NoMethodError when using content_type params with Integer value #2077

@dentarg

Description

@dentarg

This app

require "bundler/inline"

gemfile(true) do
  gem "nio4r"
  gem "sinatra", require: "sinatra/base"
end

class App < Sinatra::Base
  get "/" do
    content_type "foo/bar", baz: 1
    body "OK"
  end
end

run App

Blows up like this

$ puma content_type_bug.ru -p 8888
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23]
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 12998
Resolving dependencies...
* Listening on http://0.0.0.0:8888
Use Ctrl-C to stop
2025-01-05 09:52:35 - NoMethodError - undefined method `=~' for an instance of Integer (NoMethodError):
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:401:in `block in content_type'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `each'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `map'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `content_type'
	content_type_bug.ru:10:in `block in <class:App>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions