Skip to content

Headers with parameters which lack = raise a NoMethodError #2250

@AllyMarthaJ

Description

@AllyMarthaJ

Hiya,

We're encountering an issue where we're receiving an unexpected error for a malformed header that we'd otherwise expect to default to something sensible. Take, for example, the following request:

curl -X POST https://somerackserver/rack -H "Content-Type:application/json;charset=" -d "{}" -vv

ETA we later realised down below the header being sent had charset not charset=

This is definitively malformed, but I'd have expected either charset to be nil or an empty string.

In particular, the error comes from:

[
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/media_type.rb:44:in `strip_doublequotes'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/media_type.rb:37:in `block in params'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/media_type.rb:33:in `each'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/media_type.rb:33:in `each_with_object'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/media_type.rb:33:in `params'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/request.rb:451:in `media_type_params'",
  "/usr/local/lib64/ruby/gems/3.3.0/gems/rack-3.1.7/lib/rack/request.rb:459:in `content_charset'",
...

with the error #<NoMethodError: No method 'start_with?' on instance of NilClass

I'm happy to PR a fix to add guard for nil when calling strip_doublequotes here if that's all good!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions