diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index 83d3692d..0d92fda9 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -3,6 +3,7 @@ module Compass attr_accessor :uri, :options VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/ SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png} + VALID_EXTENSIONS = ['.png'] def self.load(uri, options) klass = Compass::SpriteImporter.new @@ -89,6 +90,14 @@ module Compass end end + def validate_sprites! + files.each do |file| + unless VALID_EXTENSIONS.include? File.extname(file) + raise Compass::Error, "Invalid sprite extension only: #{VALID_EXTENSIONS.join(',')} images are allowed" + end + end + end + # Returns the sass options for this sprite def sass_options @sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self) @@ -96,6 +105,7 @@ module Compass # Returns a Sass::Engine for this sprite object def sass_engine + validate_sprites! Sass::Engine.new(content_for_images, sass_options) end diff --git a/test/fixtures/sprites/public/images/bad_extensions/ten-by-ten.gif b/test/fixtures/sprites/public/images/bad_extensions/ten-by-ten.gif new file mode 100644 index 00000000..c0ae53cc Binary files /dev/null and b/test/fixtures/sprites/public/images/bad_extensions/ten-by-ten.gif differ diff --git a/test/fixtures/sprites/public/images/bad_extensions/twenty-by-twenty.jpg b/test/fixtures/sprites/public/images/bad_extensions/twenty-by-twenty.jpg new file mode 100644 index 00000000..4e5e297f Binary files /dev/null and b/test/fixtures/sprites/public/images/bad_extensions/twenty-by-twenty.jpg differ diff --git a/test/units/sprites/importer_test.rb b/test/units/sprites/importer_test.rb index 04f95c8b..d25bff1e 100644 --- a/test/units/sprites/importer_test.rb +++ b/test/units/sprites/importer_test.rb @@ -46,4 +46,21 @@ class ImporterTest < Test::Unit::TestCase assert_equal 'bar', @importer.sass_options[:foo] end + test "should fail givin bad sprite extensions" do + @images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images') + file = StringIO.new("images_path = #{@images_src_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") + importer = Compass::SpriteImporter.new(:uri => 'bad_extensions/*.jpg', :options => options) + begin + importer.sass_engine + assert false, "Somthing happened an invalid sprite file made it past validation" + rescue Compass::Error => e + assert e.message.include?('.png') + end + end + + def taredown + Compass.reset_configuration! + end + end \ No newline at end of file