mime-types / ruby-mime-types

Ruby MIME type registry library
Other
324 stars 122 forks source link

MIME::Types[/regex/]: Exception thrown for unmatched regex #134

Closed TheDeepestSpace closed 6 years ago

TheDeepestSpace commented 6 years ago
MIME::Types[/regex_that_wont_match/]
=> NoMethodError: undefined method `sort' for nil:NilClass
        from /var/lib/gems/2.3.0/gems/mime-types-3.1/lib/mime/types.rb:132:in `[]'
        from /var/lib/gems/2.3.0/gems/mime-types-3.1/lib/mime/types/registry.rb:13:in `[]'
    ...

looks like match function returns nil when no matches were found: https://github.com/mime-types/ruby-mime-types/blob/8de8dbb6ed312e33a746282757a9af50cb0cbc0d/lib/mime/types.rb#L216-L220 to be more specific:

[].inject(:+)
=> nil

nil value then gets assigned to matches variable: https://github.com/mime-types/ruby-mime-types/blob/8de8dbb6ed312e33a746282757a9af50cb0cbc0d/lib/mime/types.rb#L123-L134 then matches gets passed to prune_matches function, that would also return nil if matches parameter is set to nil: https://github.com/mime-types/ruby-mime-types/blob/8de8dbb6ed312e33a746282757a9af50cb0cbc0d/lib/mime/types.rb#L210-L214 a sort function is called on the returned nil, producing the error here: https://github.com/mime-types/ruby-mime-types/blob/8de8dbb6ed312e33a746282757a9af50cb0cbc0d/lib/mime/types.rb#L132

halostatue commented 6 years ago

Related to #117 and #127.

halostatue commented 6 years ago

Resolved with edf3cd7.