Commit f1d06898 by caneroj1 Committed by Jon Yurek

addressed issue #1324 for URL escaping of (, ), [, and ] characters.

parent 35f0005f
......@@ -58,7 +58,7 @@ module Paperclip
end
def escape_url(url)
(url.respond_to?(:escape) ? url.escape : URI.escape(url)).gsub(/(\/.+)\?(.+\.)/, '\1%3F\2')
(url.respond_to?(:escape) ? url.escape : URI.escape(url)).gsub(/(\/.+)\?(.+\.)/, '\1%3F\2').gsub(/\(/, '%28').gsub(/\)/, '%29').gsub(/\[/, '%5B').gsub(/\]/, '%5D')
end
end
end
......@@ -183,4 +183,17 @@ describe Paperclip::UrlGenerator do
assert mock_interpolator.has_interpolated_pattern?(expected),
"expected the interpolator to be passed #{expected.inspect} but it wasn't"
end
it "should be able to escape (, ), [, and ]." do
expected = "the(expected)result[]"
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
def url_generator.respond_to(params)
false if params == :escape
end
result = url_generator.for(:style_name, {escape: true})
assert_equal "the%28expected%29result%5B%5D", result
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment