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

Commit

Permalink
Timestamps were improperly escaped
Browse files Browse the repository at this point in the history
Swaps the timestamp and escaping methods

Fixes #126
  • Loading branch information
ScotterC committed Feb 6, 2015
1 parent 223a265 commit 468bd37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
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

0 comments on commit 468bd37

Please sign in to comment.