Commit 51f37a11 by Dan Collis-Puro Committed by Jon Yurek

Update regexes to bind to beginning and end of string

This ensures that multiline strings are properly matched in their
entirety.
parent 1c9d2e8b
......@@ -48,7 +48,7 @@ module Paperclip
# Returns the interpolated URL. Will raise an error if the url itself
# contains ":url" to prevent infinite recursion. This interpolation
# is used in the default :path to ease default specifications.
RIGHT_HERE = "#{__FILE__.gsub(%r{^\./}, "")}:#{__LINE__ + 3}"
RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, "")}:#{__LINE__ + 3}"
def url attachment, style_name
raise Errors::InfiniteInterpolationError if caller.any?{|b| b.index(RIGHT_HERE) }
attachment.url(style_name, :timestamp => false, :escape => false)
......@@ -90,7 +90,7 @@ module Paperclip
# Returns the basename of the file. e.g. "file" for "file.jpg"
def basename attachment, style_name
attachment.original_filename.gsub(/#{Regexp.escape(File.extname(attachment.original_filename))}$/, "")
attachment.original_filename.gsub(/#{Regexp.escape(File.extname(attachment.original_filename))}\Z/, "")
end
# Returns the extension of the file. e.g. "jpg" for "file.jpg"
......@@ -98,7 +98,7 @@ module Paperclip
# of the actual extension.
def extension attachment, style_name
((style = attachment.styles[style_name.to_s.to_sym]) && style[:format]) ||
File.extname(attachment.original_filename).gsub(/^\.+/, "")
File.extname(attachment.original_filename).gsub(/\A\.+/, "")
end
# Returns an extension based on the content type. e.g. "jpeg" for
......@@ -128,7 +128,7 @@ module Paperclip
# It's possible, though unlikely, that the mime type is not in the
# database, so just use the part after the '/' in the mime type as the
# extension.
%r{/([^/]*)$}.match(attachment.content_type)[1]
%r{/([^/]*)\Z}.match(attachment.content_type)[1]
end
end
......
module Paperclip
class DataUriAdapter < StringioAdapter
REGEXP = /^data:([-\w]+\/[-\w\+]+);base64,(.*)/m
REGEXP = /\Adata:([-\w]+\/[-\w\+]+);base64,(.*)/m
def initialize(target_uri)
@target_uri = target_uri
......
module Paperclip
class HttpUrlProxyAdapter < UriAdapter
REGEXP = /^https?:\/\//
REGEXP = /\Ahttps?:\/\//
def initialize(target)
super(URI(target))
......
......@@ -43,8 +43,8 @@ module Paperclip
end unless defined?(Fog)
base.instance_eval do
unless @options[:url].to_s.match(/^:fog.*url$/)
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system\//, '')
unless @options[:url].to_s.match(/\A:fog.*url\Z/)
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system\//, '')
@options[:url] = ':fog_public_url'
end
Paperclip.interpolates(:fog_public_url) do |attachment, style|
......@@ -53,7 +53,7 @@ module Paperclip
end
end
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\Z))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]\Z/
def exists?(style = default_style)
if original_filename
......
......@@ -149,8 +149,8 @@ module Paperclip
@s3_server_side_encryption = @options[:s3_server_side_encryption].to_s.upcase
end
unless @options[:url].to_s.match(/^:s3.*url$/) || @options[:url] == ":asset_host"
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system/, '')
unless @options[:url].to_s.match(/\A:s3.*url\Z/) || @options[:url] == ":asset_host"
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system/, '')
@options[:url] = ":s3_path_url"
end
@options[:url] = @options[:url].inspect if @options[:url].is_a?(Symbol)
......@@ -159,16 +159,16 @@ module Paperclip
end
Paperclip.interpolates(:s3_alias_url) do |attachment, style|
"#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{\A/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_alias_url
Paperclip.interpolates(:s3_path_url) do |attachment, style|
"#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{\A/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_path_url
Paperclip.interpolates(:s3_domain_url) do |attachment, style|
"#{attachment.s3_protocol(style, true)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.s3_protocol(style, true)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{\A/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_domain_url
Paperclip.interpolates(:asset_host) do |attachment, style|
"#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.path(style).gsub(%r{\A/}, "")}"
end unless Paperclip::Interpolations.respond_to? :asset_host
end
......@@ -244,7 +244,7 @@ module Paperclip
end
def s3_object style_name = default_style
s3_bucket.objects[path(style_name).sub(%r{^/},'')]
s3_bucket.objects[path(style_name).sub(%r{\A/},'')]
end
def using_http_proxy?
......@@ -352,7 +352,7 @@ module Paperclip
@queued_for_delete.each do |path|
begin
log("deleting #{path}")
s3_bucket.objects[path.sub(%r{^/},'')].delete
s3_bucket.objects[path.sub(%r{\A/},'')].delete
rescue AWS::Errors::Base => e
# Ignore this.
end
......@@ -397,10 +397,10 @@ module Paperclip
http_headers = http_headers.call(instance) if http_headers.respond_to?(:call)
http_headers.inject({}) do |headers,(name,value)|
case name.to_s
when /^x-amz-meta-(.*)/i
when /\Ax-amz-meta-(.*)/i
s3_metadata[$1.downcase] = value
else
s3_headers[name.to_s.downcase.sub(/^x-amz-/,'').tr("-","_").to_sym] = value
s3_headers[name.to_s.downcase.sub(/\Ax-amz-/,'').tr("-","_").to_sym] = value
end
end
end
......
module Paperclip
class TempfileFactory
ILLEGAL_FILENAME_CHARACTERS = /^~/
ILLEGAL_FILENAME_CHARACTERS = /\A~/
def generate(name)
@name = name
......
......@@ -30,7 +30,7 @@ module Paperclip
options = attributes.extract_options!.dup
Paperclip::Validators.constants.each do |constant|
if constant.to_s =~ /^Attachment(.+)Validator$/
if constant.to_s =~ /\AAttachment(.+)Validator\Z/
validator_kind = $1.underscore.to_sym
if options.has_key?(validator_kind)
......
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