Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CacheBustingFilter: better handling of dots in file names

  • Loading branch information...
commit ba0b8a00356b4c854930a8e849b5629d51ffd70f 1 parent fd11d96
James A. Rosen authored
View
3  lib/rake-pipeline-web-filters/cache_buster_filter.rb
@@ -25,7 +25,8 @@ def initialize(&key_generator)
key_generator ||= DEFAULT_KEY_GENERATOR
output_name_generator = proc { |path, file|
parts = path.split('.')
- parts[0] << "-#{key_generator.call(file)}"
+ index_to_modify = parts.length > 1 ? -2 : -1
+ parts[index_to_modify] << "-#{key_generator.call(file)}"
parts.join('.')
}
super(&output_name_generator)
View
33 spec/cache_buster_filter_spec.rb
@@ -69,4 +69,37 @@ def setup_filter(filter)
end
end
+
+ describe 'for an input file with multiple dots' do
+ let(:input_file) {
+ MemoryFileWrapper.new '/path/to/input', 'my.text.file.txt', 'UTF-8', content
+ }
+
+ let(:output_file) {
+ MemoryFileWrapper.new output_root, "my.text.file-foo.txt", 'UTF-8'
+ }
+
+ subject { setup_filter(CacheBusterFilter.new() { 'foo' }) }
+
+ it 'appends the busting key to the penultimate part' do
+ subject.output_files.should == [ output_file ]
+ end
+ end
+
+ describe 'for an input file with no dots' do
+ let(:input_file) {
+ MemoryFileWrapper.new '/path/to/input', 'my_text_file', 'UTF-8', content
+ }
+
+ let(:output_file) {
+ MemoryFileWrapper.new output_root, "my_text_file-foo", 'UTF-8'
+ }
+
+ subject { setup_filter(CacheBusterFilter.new() { 'foo' }) }
+
+ it 'appends the busting key to the end of the filename' do
+ subject.output_files.should == [ output_file ]
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.