diff --git a/Gemfile.lock b/Gemfile.lock index ba867187..24340b69 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT PATH remote: . specs: - compass (0.11.beta.4.29656ea) + compass (0.11.beta.5.7571d4a) chunky_png (~> 1.1.0) sass (>= 3.1.0.alpha.249) diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index 3890135c..f2106739 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -1,7 +1,7 @@ module Compass class SpriteMap attr_reader :uri, :options - + VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/ def find_relative(*args) nil @@ -30,7 +30,13 @@ module Compass # Returns an Array of image names without the file extension def sprite_names - @sprite_names ||= files.collect { |file| File.basename(file, '.png') } + @sprite_names ||= files.collect do |file| + filename = File.basename(file, '.png') + unless VAILD_FILE_NAME =~ filename + raise Compass::Error, "Sprite file names must be legal css identifiers. Please rename #{File.basename(file)}" + end + filename + end end # Returns the sass options for this sprite diff --git a/spec/sprites_spec.rb b/spec/sprites_spec.rb index 0c30f68b..61a0d3f4 100644 --- a/spec/sprites_spec.rb +++ b/spec/sprites_spec.rb @@ -496,7 +496,7 @@ describe Compass::Sprites do css = render <<-SCSS @import "selectors/*.png"; a { - @include selectors_sprite(ten-by-ten) + @include selectors-sprite(ten-by-ten) } SCSS css.should == <<-CSS @@ -518,5 +518,17 @@ describe Compass::Sprites do } CSS end + + it "should raise error on filenames that are not valid sass syntax" do + lambda do + render <<-SCSS + $sprite-file-prefix:'foo'; + @import "prefix/*.png"; + a { + @include squares-sprite(20-by-20) + } + SCSS + end.should raise_error Compass::Error + end end