Skip to content
New issue

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

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

Already on GitHub? # to your account

Case Sensitive Issue In Regex #2201

Merged
merged 1 commit into from
Jun 29, 2017
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
3 changes: 2 additions & 1 deletion lib/carrierwave/uploader/extension_whitelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def check_extension_whitelist!(new_file)
end

def whitelisted_extension?(extension)
Array(extension_whitelist).any? { |item| extension =~ /\A#{item}\z/i }
downcase_extension = extension.downcase
Array(extension_whitelist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
end

end # ExtensionWhitelist
Expand Down
8 changes: 8 additions & 0 deletions spec/uploader/extension_whitelist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
@uploader.cache!(File.open(file_path('test.jpeg')))
}).not_to raise_error
end

it "accepts extensions as regular expressions in a case insensitive manner" do

allow(@uploader).to receive(:extension_whitelist).and_return([/jpe?g/, 'gif', 'png'])
expect(running {
@uploader.cache!(File.open(file_path('case.JPG')))
}).not_to raise_error
end
end

context "when the whitelist is a single value" do
Expand Down