Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved regex, requires colon or whitespace before url

  • Loading branch information...
commit f791bdbb758d5797c65b0b25aea664bd6212b304 1 parent 9570484
@carlhoerberg authored
Showing with 19 additions and 8 deletions.
  1. +4 −4 lib/sprockets-urlrewriter.rb
  2. +15 −4 spec/urlrewriter_spec.rb
View
8 lib/sprockets-urlrewriter.rb
@@ -13,10 +13,10 @@ def evaluate(context, locals)
logical_path = context.instance_variable_get(:@logical_path)
rel = Pathname.new(logical_path).parent
- data.gsub /:\s*url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/i do |url|
- next url if URI.parse($1).absolute?
- new_path = rel.join Pathname.new($1)
- ": url(#{new_path}#{$2})"
+ data.gsub /(:|\s)url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/i do |url|
+ next url if URI.parse($2).absolute?
+ new_path = rel.join Pathname.new($2)
+ "#{$1}url(#{new_path}#{$3})"
end
end
end
View
19 spec/urlrewriter_spec.rb
@@ -31,15 +31,26 @@
assert_equal "body { background-url: url(/assets/css/image.png) }", subject
end
- it 'ignores whitespace between : and url' do
+ it 'allows whitespace between : and url' do
@css = "body { background-url: url('image.png') }"
- assert_equal "body { background-url: url(/assets/css/image.png) }", subject
+ assert_equal "body { background-url: url(/assets/css/image.png) }", subject
end
- it 'ignores newline between : and url' do
+ it 'allows newline between colon and url' do
@css = "body { background-url:
url('image.png') }"
- assert_equal "body { background-url: url(/assets/css/image.png) }", subject
+ assert_equal "body { background-url:
+url(/assets/css/image.png) }", subject
+ end
+
+ it 'allows nospace between colon and url' do
+ @css = "body { background-url:url('image.png') }"
+ assert_equal "body { background-url:url(/assets/css/image.png) }", subject
+ end
+
+ it 'allows things between colon and url' do
+ @css = "body { background: no-repeat url('image.png') }"
+ assert_equal "body { background: no-repeat url(/assets/css/image.png) }", subject
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.