Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle \n in MIME::Types.type_for #178

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ jobs:
- jruby
- jruby-head
- truffleruby
- truffleruby-head
- truffleruby+graalvm
- truffleruby+graalvm-head
include:
- ruby: head
continue-on-error: true
Expand All @@ -45,6 +43,13 @@ jobs:
ruby: '3.1'
- os: ubuntu-22.04
ruby: '3.2'
- os: ubuntu-22.04
ruby: truffleruby+graalvm-head
continue-on-error: true
- os: ubuntu-22.04
ruby: truffleruby-head
continue-on-error: true

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.continue-on-error || false }}
steps:
Expand Down
10 changes: 10 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 3.5.1 / 2023-08-21

- 1 bug fix:

- Better handle possible line-termination strings (legal in Unix filenames)
such as `\n` in `MIME::Types.type_for`. Reported by ooooooo-q in [#177][],
resolved in [#178][].

## 3.5.0 / 2023-08-07

- 1 minor enhancement:
Expand Down Expand Up @@ -304,6 +312,8 @@
[#166]: https://github.com/mime-types/ruby-mime-types/issues/166
[#167]: https://github.com/mime-types/ruby-mime-types/pull/167
[#170]: https://github.com/mime-types/ruby-mime-types/pull/170
[#177]: https://github.com/mime-types/ruby-mime-types/issues/177
[#178]: https://github.com/mime-types/ruby-mime-types/pull/178
[code-of-conduct.md]: Code-of-Conduct_md.html
[contributor covenant]: http://contributor-covenant.org
[mime-types-data]: https://github.com/mime-types/mime-types-data
2 changes: 1 addition & 1 deletion lib/mime/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def to_s
end

# The released version of the mime-types library.
VERSION = "3.5.0"
VERSION = "3.5.1"

include Comparable

Expand Down
2 changes: 1 addition & 1 deletion lib/mime/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def [](type_id, complete: false, registered: false)
# => [application/xml, image/gif, text/xml]
def type_for(filename)
Array(filename).flat_map { |fn|
@extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
@extension_index[fn.chomp.downcase[/\.?([^.]*?)\z/m, 1]]
}.compact.inject(Set.new, :+).sort { |a, b|
a.priority_compare(b)
}
Expand Down
4 changes: 4 additions & 0 deletions test/test_mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def mime_types
plain_text.add_extensions("xtxt")
assert_includes mime_types.type_for("xtxt"), "text/plain"
end

it "handles newline characters correctly" do
assert_includes mime_types.type_for("test.pdf\n.txt"), "text/plain"
end
end

describe "#count" do
Expand Down
5 changes: 5 additions & 0 deletions test/test_mime_types_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def setup
plain_text.add_extensions("xtxt")
assert_includes MIME::Types.type_for("xtxt"), "text/plain"
end

it "handles newline characters correctly" do
assert_includes MIME::Types.type_for("test.pdf\n.txt"), "text/plain"
assert_includes MIME::Types.type_for("test.txt\n.pdf"), "application/pdf"
end
end

describe ".count" do
Expand Down
Loading