Skip to content

Commit

Permalink
URL-escape resource filenames in stacks urls
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 12, 2018
1 parent 31653e4 commit 329309a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/embed/stacks_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def stacks_image_url(druid, file_name)
private

def normalized_stacks_image_file_name(file_name)
file_name.gsub(/\.\w+$/, '')
ERB::Util.url_encode(file_name.gsub(/\.\w+$/, ''))
end
end
end
8 changes: 8 additions & 0 deletions spec/lib/embed/stacks_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@
it 'accpets an optional size parameter' do
expect(subject.stacks_square_url('abc123', 'filename.jpg', size: 50)).to match(%r{square/50,50/})
end

it 'escapes special characters in the image file name' do
expect(subject.stacks_square_url('abc123', 'file name.jpg')).to match(/file%20name/)
end
end

describe '#stacks_thumb_url' do
it 'requests an image that is 400px on the long edge' do
expect(subject.stacks_thumb_url('abc123', 'filename.jpg')).to match(%r{/full/\!400,400/})
end

it 'escapes special characters in the image file name' do
expect(subject.stacks_thumb_url('abc123', 'file name.jpg')).to match(/file%20name/)
end
end
end

0 comments on commit 329309a

Please sign in to comment.