summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/pic.rb
diff options
context:
space:
mode:
authormarc <[email protected]>2015-07-03 16:44:45 +0200
committermarc <[email protected]>2015-07-03 16:44:45 +0200
commitc7c7937dcde9a94f2e5ee0549451b34e410803e0 (patch)
treed06ccd49055e1474891a6b3d3d190e457e7e2304 /lib/axlsx/drawing/pic.rb
parent1bec39cebaef6a98481f52587ecc0483b4defc08 (diff)
downloadcaxlsx-c7c7937dcde9a94f2e5ee0549451b34e410803e0.tar.gz
caxlsx-c7c7937dcde9a94f2e5ee0549451b34e410803e0.zip
Validates whether an image is acceptable through mime type
image/jpeg, image/png & image/gif are considered the allowed mime types for an image. mimemagic gem is added as dependency in order to do the checking. Added tests to check against three supported mime types. A fake jpg fixture (created with 'touch' command) has been added to test that extension is no longer used.
Diffstat (limited to 'lib/axlsx/drawing/pic.rb')
-rw-r--r--lib/axlsx/drawing/pic.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index 571e9047..b090c661 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -25,8 +25,8 @@ module Axlsx
@picture_locking = PictureLocking.new(options)
end
- # allowed file extenstions
- ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg']
+ # allowed mime types
+ ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif)
# The name to use for this picture
# @return [String]
@@ -67,7 +67,7 @@ module Axlsx
def image_src=(v)
Axlsx::validate_string(v)
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v.downcase).delete('.')
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeMagic.by_magic(File.open(v)).to_s
raise ArgumentError, "File does not exist" unless File.exist?(v)
@image_src = v
end