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

Use Marcel::Magic.new(content_type).extensions instead of Marcel::TYPES[content_type] #2728

Merged
merged 4 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion carrierwave.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency "activesupport", ">= 6.0.0"
s.add_dependency "activemodel", ">= 6.0.0"
s.add_dependency "image_processing", "~> 1.1"
s.add_dependency "marcel", "~> 1.0.0"
s.add_dependency "marcel", "~> 1.0.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new code change, you don't need to make this version change, because the code is supported as far back as version 1.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this change 👍🏻

s.add_dependency "addressable", "~> 2.6"
s.add_dependency "ssrf_filter", "~> 1.0"
s.add_development_dependency "csv", "~> 3.0"
Expand Down
6 changes: 3 additions & 3 deletions lib/carrierwave/downloader/remote_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def headers

def original_filename
filename = filename_from_header || filename_from_uri
mime_type = Marcel::TYPES[content_type]
unless File.extname(filename).present? || mime_type.blank?
extension = mime_type[0].first
extensions = Marcel::TYPE_EXTS[content_type]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extensions = Marcel::TYPE_EXTS[content_type]
extensions = Marcel::Magic.new(content_type).extensions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is much nicer 😄

unless File.extname(filename).present? || extensions.blank?
extension = extensions.first
filename = "#{filename}.#{extension}"
end
filename
Expand Down
2 changes: 1 addition & 1 deletion spec/processing/rmagick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def foo=(value); raise; end
instance.manipulate! :read => {
:foo => "1"
}
end.to raise_error NoMethodError, /private method `foo=' called/
end.to raise_error NoMethodError, /private method .foo=. called/
end
end

Expand Down