diff options
| author | Randy Morgan <[email protected]> | 2013-08-17 13:51:53 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2013-08-17 13:51:53 +0900 |
| commit | 7b6a28906a5d19696cd3fcbc35759ccb157dc6df (patch) | |
| tree | 1c47bab700f96633e5d1cab5fa7ffa1ce16ed065 | |
| parent | 3411a6d22a228e7170e4058d1d1715ef507ccffb (diff) | |
| download | caxlsx-7b6a28906a5d19696cd3fcbc35759ccb157dc6df.tar.gz caxlsx-7b6a28906a5d19696cd3fcbc35759ccb157dc6df.zip | |
updated image source validation to use lower case comparison of accepted file extensions
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 7 | ||||
| -rw-r--r-- | test/drawing/tc_pic.rb | 12 |
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 89f4c1ea..a6c85705 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -37,7 +37,7 @@ module Axlsx attr_reader :descr # The path to the image you want to include - # Only local images are supported at this time and only jpg support + # Only local images are supported at this time. # @return [String] attr_reader :image_src @@ -67,7 +67,7 @@ module Axlsx def image_src=(v) Axlsx::validate_string(v) - RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.') + RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v.downcase).delete('.') raise ArgumentError, "File does not exist" unless File.exist?(v) @image_src = v end @@ -89,7 +89,8 @@ module Axlsx # @return [String] def extname File.extname(image_src).delete('.') unless image_src.nil? - end + end + # The index of this image in the workbooks images collections # @return [Index] def index diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index 79a3194d..af8f6f57 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -21,21 +21,21 @@ class TestPic < Test::Unit::TestCase def test_anchor_swapping #swap from one cell to two cell when end_at is specified assert(@image.anchor.is_a?(Axlsx::OneCellAnchor)) - start_at = @image.anchor.from + start_at = @image.anchor.from @image.end_at 10,5 assert(@image.anchor.is_a?(Axlsx::TwoCellAnchor)) assert_equal(start_at.col, @image.anchor.from.col) assert_equal(start_at.row, @image.anchor.from.row) assert_equal(10,@image.anchor.to.col) assert_equal(5, @image.anchor.to.row) - + #swap from two cell to one cell when width or height are specified @image.width = 200 assert(@image.anchor.is_a?(Axlsx::OneCellAnchor)) assert_equal(start_at.col, @image.anchor.from.col) assert_equal(start_at.row, @image.anchor.from.row) assert_equal(200, @image.width) - + end def test_hyperlink assert_equal(@image.hyperlink.href, "https://github.com/randym") @@ -76,6 +76,10 @@ class TestPic < Test::Unit::TestCase assert_equal(@image.image_src, @test_img) end + def test_image_src_downcase + assert_nothing_raised { @image.image_src = @test_img.upcase } + end + def test_descr assert_raise(ArgumentError) { @image.descr = 49 } assert_nothing_raised { @image.descr = "test" } @@ -98,5 +102,5 @@ class TestPic < Test::Unit::TestCase doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string) assert_equal r_id, doc.xpath("//a:blip").first["r:embed"] end - + end |
