Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Timestamps were improperly escaped #133

Merged
merged 1 commit into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/delayed_paperclip/url_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ def self.included(base)
def for_with_processed(style_name, options)
most_appropriate_url = @attachment.processing_style?(style_name) ? most_appropriate_url(style_name) : most_appropriate_url_without_processed

escape_url_as_needed(
timestamp_as_needed(
timestamp_as_needed(
escape_url_as_needed(
@attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
options
), options)
),
options)
end

# This method is a mess
Expand Down
26 changes: 26 additions & 0 deletions spec/delayed_paperclip/url_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@
expect(attachment.url(:online)).to eql "/system/dummies/images/000/000/001/online/12k.png"
end
end

context "should be able to escape (, ), [, and ]." do
def generate(expected, updated_at=nil)
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(attachment, options)
attachment.stubs(:updated_at).returns updated_at
url_generator.for(:style_name, {escape: true, timestamp: !!updated_at})
end


it "interpolates correctly without timestamp" do
expect(
"the%28expected%29result%5B%5D"
).to be == generate("the(expected)result[]")
end

it "does not interpolate timestamp" do
expected = "the(expected)result[]"
updated_at = 1231231234

expect(
"the%28expected%29result%5B%5D?#{updated_at}"
).to be == generate(expected, updated_at)
end
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'delayed_paperclip/railtie'
DelayedPaperclip::Railtie.insert



# silence deprecation warnings in rails 4.2
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
ActiveRecord::Base.raise_in_transactional_callbacks = true
Expand All @@ -49,6 +51,10 @@
config.run_all_when_everything_filtered = true
end

# In order to not duplicate code directly from Paperclip's spec support
# We're requiring the MockInterpolator object to be used
require Gem.find_files("../spec/support/mock_interpolator").first

Dir["./spec/integration/examples/*.rb"].sort.each {|f| require f}

# Reset table and class with image_processing column or not
Expand Down