lib/paperclip/interpolations.rb in paperclip-3.5.2 vs lib/paperclip/interpolations.rb in paperclip-3.5.3

- old
+ new

@@ -46,11 +46,11 @@ end # 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) end @@ -88,19 +88,19 @@ plural_cache.underscore_and_pluralize(attachment.instance.class.to_s) end # 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" # If the style has a format defined, it will return the format instead # 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 # "image/jpeg". If the style has a specified format, it will override the # content-type detection. @@ -126,10 +126,10 @@ extensions_for_mime_type.first else # 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 # Returns the id of the instance. def id attachment, style_name