Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully merged #2

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5d7f265
ignore invalid content-disposition header
arokettu Aug 23, 2016
dfc9927
fix warning from hound
arokettu Aug 23, 2016
036f330
Fix HTTP Proxy option passed to AWS SDK, which cnanged in version 2
douglaslise Apr 29, 2017
9c32d3f
Update paperclip_generator.rb
Arinzeokeke May 14, 2017
0ef9ee2
Update paperclip_migration.rb.erb
Arinzeokeke May 14, 2017
71e3a3e
Update NEWS
Arinzeokeke May 14, 2017
e67fe5e
Update paperclip_generator.rb
Arinzeokeke May 14, 2017
0d71952
Update paperclip_migration.rb.erb
Arinzeokeke May 14, 2017
079fb34
Update paperclip_generator.rb
Arinzeokeke May 14, 2017
3d3dbdc
Add migration_version variable to migration generator for rails 5 com…
jackellenberger Jul 18, 2017
d5a6ffa
Update syntax to satisfy hound
jackellenberger Jul 18, 2017
cc45010
Added support for aws-sdk-s3 gem which is now preferred way to intera…
morgoth Aug 31, 2017
d538183
Drop support for aws-sdk gem
morgoth Sep 15, 2017
3ac76c5
Update media_type_spoof_detector.rb
vikascoupa Oct 18, 2017
1e5f2b1
Update media_type_spoof_detector.rb
vikascoupa Oct 18, 2017
0089f53
Update media_type_spoof_detector.rb
vikascoupa Oct 18, 2017
8253c89
Remove bad exception handling!
gaurish Aug 2, 2017
c794f6d
Be more explicit
gaurish Oct 25, 2017
b88dcce
Rename FactoryGirl to FactoryBot
itsdawnbois Oct 26, 2017
0fce4ae
Change default url to nil, for two reasons:
johnnyshields Nov 4, 2017
30d1d04
fix code comment
johnnyshields Nov 4, 2017
7133e89
Fix migration generator for versioned migrations in the Rails 5.
aditya-kapoor Oct 3, 2017
dc2065a
Add specs for rails environment.
aditya-kapoor Oct 9, 2017
baa3c3c
Also match filenames without quotes
basschoen Nov 17, 2017
626b4fb
Update uri_adapter.rb
basschoen Nov 17, 2017
cb03ec5
Remove magic comment
hash52 Nov 22, 2017
439a5a2
Merge s3 changes from morgoth
DaveEOS Dec 18, 2017
ccc54d6
Merge branch 'default-url-nil' of github.com:johnnyshields/paperclip …
DaveEOS Dec 18, 2017
f40b2e5
Merge branch '2283-ignore-invalid-content-disposition' of github.com:…
DaveEOS Dec 18, 2017
fd1d9b5
Merge branch 'master' of github.com:hash52/paperclip into fully_merged
DaveEOS Dec 18, 2017
24af87d
Merge branch 'master' of github.com:eldemonstro/paperclip into fully_…
DaveEOS Dec 18, 2017
dfa36f1
Merge branch 'patch-1' of github.com:basschoen/paperclip into fully_m…
DaveEOS Dec 18, 2017
215a0ed
Merge branch 'master' of github.com:vikascoupa/paperclip into fully_m…
DaveEOS Dec 18, 2017
21b838c
Merge branch 'fix-migration-generator' of github.com:aditya-kapoor/pa…
DaveEOS Dec 18, 2017
7961365
Merging jackellenberger:master PR 2470
DaveEOS Dec 18, 2017
8a70a60
Merging Arinzeokeke:master PR 2447
DaveEOS Dec 18, 2017
73b5fdf
Merge branch 'fix-s3-proxy-option' of github.com:douglaslise/papercli…
DaveEOS Dec 18, 2017
3e1fb34
Fix bundler version in travis config
DaveEOS Jan 24, 2018
63d7c38
Fix bundler version in travis config
DaveEOS Jan 24, 2018
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ rvm:

# FIXME: fails with modern bundler
before_install:
- rvm @global do gem uninstall bundler -a -x
- rvm @global do gem install bundler -v 1.12.5
- rvm @global do gem uninstall bundler -a -x || true
- rvm @global do gem install bundler -v 1.12.5 || true

script: "bundle exec rake clean spec cucumber"

Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ master:
`CLASS=User rake paperclip:refresh:fingerprints`
You can optionally limit the attachment that will be processed, e.g:
`CLASS=User ATTACHMENT=avatar rake paperclip:refresh:fingerprints`
* Improvement: Added support for preferred gem for s3 `aws-sdk-s3`

5.1.0 (2016-08-19):

Expand All @@ -39,6 +40,7 @@ master:
* Add `read_timeout` option to `UriAdapter#download_content` method [#2232]
* Fix a nil error in content type validation matcher [#1910]
* Documentation improvements
* Add Rails Version to migration file. Required in Rails 5+

5.0.0.beta2 (2016-04-01):

Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ module YourApp
class Application < Rails::Application
# Other code...

config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
config.paperclip_defaults = { storage: :fog,
fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"},
fog_directory: "",
fog_host: "localhost",
default_url: "/:attachment/:style/missing.png" }
end
end
```
Expand All @@ -484,6 +488,7 @@ Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
Paperclip::Attachment.default_options[:default_url] = "/:attachment/:style/missing.png"
```
---

Expand Down Expand Up @@ -563,7 +568,7 @@ Storage
Paperclip ships with 3 storage adapters:

* File Storage
* S3 Storage (via `aws-sdk`)
* S3 Storage (via `aws-sdk-s3`)
* Fog Storage

If you would like to use Paperclip with another storage, you can install these
Expand All @@ -589,10 +594,10 @@ _**NOTE**: This is a change from previous versions of Paperclip, but is overall
safer choice for the default file store._

You may also choose to store your files using Amazon's S3 service. To do so, include
the `aws-sdk` gem in your Gemfile:
the `aws-sdk-s3` gem in your Gemfile:

```ruby
gem 'aws-sdk', '~> 2.3.0'
gem 'aws-sdk-s3'
```

And then you can specify using S3 from `has_attached_file`.
Expand Down Expand Up @@ -955,7 +960,7 @@ similar mechanism for whichever parallel testing library you use.

**Integration Tests**

Using integration tests with FactoryGirl may save multiple copies of
Using integration tests with FactoryBot may save multiple copies of
your test files within the app. To avoid this, specify a custom path in
the `config/environments/test.rb` like so:

Expand All @@ -972,11 +977,11 @@ config.after(:suite) do
end
```

**Example of test configuration with Factory Girl**
**Example of test configuration with Factory Bot**


```ruby
FactoryGirl.define do
FactoryBot.define do
factory :user do
avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
end
Expand Down
16 changes: 16 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
##################################################
# DEPRECATION NOTICE #
##################################################

The 6.x version of Paperclip will change the behavior of the `:default_url`
to be nil. In 5.x and earlier it is defaulted to 'missing.png'

You can migrate to the new behavior now by adding to an initializer:

Paperclip::Attachment.default_options[:default_url] = nil

Alternatively, you can preserve existing behavior by adding:

Paperclip::Attachment.default_options[:default_url] = '/:attachment/:style/missing.png'


##################################################
# NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
##################################################
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
gem "jruby-openssl", :platform => :jruby
gem "capybara"
gem "gherkin"
gem "aws-sdk", "~> 2.0.0"
gem "aws-sdk-s3"
gem "racc", :platform => :rbx
gem "rubysl", :platform => :rbx
"""
Expand Down
10 changes: 9 additions & 1 deletion lib/generators/paperclip/paperclip_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def self.source_root
end

def generate_migration
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}"
migration_template("paperclip_migration.rb.erb",
"db/migrate/#{migration_file_name}",
migration_version: migration_version)
end

def migration_name
Expand All @@ -27,4 +29,10 @@ def migration_file_name
def migration_class_name
migration_name.camelize
end

def migration_version
if Rails.version.start_with? "5"
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
end
end
4 changes: 4 additions & 0 deletions lib/generators/paperclip/templates/paperclip_migration.rb.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<% if Paperclip::RailsEnvironment.version5? %>
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
<% else %>
class <%= migration_class_name %> < ActiveRecord::Migration
<% end %>
def self.up
change_table :<%= table_name %> do |t|
<% attachment_names.each do |attachment| -%>
Expand Down
10 changes: 5 additions & 5 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ module ClassMethods
# Note: When using the +s3+ storage option, the +url+ option expects
# particular values. See the Paperclip::Storage::S3#url documentation for
# specifics.
# * +default_url+: The URL that will be returned if there is no attachment assigned.
# This field is interpolated just as the url is. The default value is
# "/:attachment/:style/missing.png"
# has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png"
# User.new.avatar_url(:small) # => "/images/default_small_avatar.png"
# * +default_url+: The URL that will be returned if there is no attachment assigned,
# useful for "missing" images. This field is interpolated just as the url is.
# The default value is nil.
# has_attached_file :avatar, :default_url => "/:attachment/missing_avatar_:style.png"
# User.new.avatar_url(:small) # => "/images/missing_avatar_small.png"
# * +styles+: A hash of thumbnail styles and their geometries. You can find more about
# geometry strings at the ImageMagick website
# (http://www.imagemagick.org/script/command-line-options.php#resize). Paperclip
Expand Down
5 changes: 2 additions & 3 deletions lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'uri'
require 'paperclip/url_generator'
require 'active_support/deprecation'
Expand All @@ -13,7 +12,7 @@ def self.default_options
@default_options ||= {
:convert_options => {},
:default_style => :original,
:default_url => "/:attachment/:style/missing.png",
:default_url => nil, # Paperclip::VERSION =~ /\A[1-5]\./ ? '/:attachment/:style/missing.png' : nil,
:escape_url => true,
:restricted_characters => /[&$+,\/:;=?@<>\[\]\{\}\|\\\^~%# ]/,
:filename_cleaner => nil,
Expand Down Expand Up @@ -53,7 +52,7 @@ def self.default_options
# +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
# +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
# a special case that indicates all styles should be processed)
# +default_url+ - a URL for the missing image
# +default_url+ - an interpolatable URL for the missing image, e.g. "/:attachment/:style/missing.png". Defaults to nil
# +default_style+ - the style to use when an argument is not specified e.g. #url, #path
# +storage+ - the storage mechanism. Defaults to :filesystem
# +use_timestamp+ - whether to append an anti-caching timestamp to image URLs. Defaults to true
Expand Down
1 change: 0 additions & 1 deletion lib/paperclip/filename_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
module Paperclip
class FilenameCleaner
def initialize(invalid_character_regex)
Expand Down
1 change: 1 addition & 0 deletions lib/paperclip/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def self.all
# an interpolation pattern for Paperclip to use.
def self.interpolate pattern, *args
pattern = args.first.instance.send(pattern) if pattern.kind_of? Symbol
return unless pattern
result = pattern.dup
interpolators_cache.each do |method, token|
result.gsub!(token) { send(method, *args) } if result.include?(token)
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/io_adapters/uri_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def content_type_from_content
def filename_from_content_disposition
if @content.meta.has_key?("content-disposition")
matches = @content.meta["content-disposition"].
match(/filename="([^"]*)"/)
match(/filename="?([^"\;]*)"?/)
matches[1] if matches
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/paperclip/media_type_spoof_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def media_types_from_name
end

def calculated_content_type
@calculated_content_type ||= type_from_file_command.chomp
type_from_file_cmd = type_from_file_command
@calculated_content_type ||= (type_from_file_cmd.chomp if !type_from_file_cmd.nil?)
end

def calculated_media_type
Expand Down
14 changes: 11 additions & 3 deletions lib/paperclip/rails_environment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module Paperclip
class RailsEnvironment
include Singleton

def self.get
new.get
instance.get
end

def self.version5?
if instance.rails_exists?
Rails.version.to_i == 5
else
false
end
end

def get
Expand All @@ -12,8 +22,6 @@ def get
end
end

private

def rails_exists?
Object.const_defined?(:Rails)
end
Expand Down
21 changes: 6 additions & 15 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Storage
# Amazon's S3 file hosting service is a scalable, easy place to store files for
# distribution. You can find out more about it at http://aws.amazon.com/s3
#
# To use Paperclip with S3, include the +aws-sdk+ gem in your Gemfile:
# gem 'aws-sdk'
# To use Paperclip with S3, include the +aws-sdk-s3+ gem in your Gemfile:
# gem 'aws-sdk-s3'
# There are a few S3-specific options for has_attached_file:
# * +s3_credentials+: Takes a path, a File, a Hash or a Proc. The path (or File) must point
# to a YAML file containing the +access_key_id+ and +secret_access_key+ that Amazon
Expand Down Expand Up @@ -95,7 +95,7 @@ module Storage
# S3 (strictly speaking) does not support directories, you can still use a / to
# separate parts of your file name.
# * +s3_host_name+: If you are using your bucket in Tokyo region etc, write host_name.
# * +s3_region+: For aws-sdk v2, s3_region is required.
# * +s3_region+: For aws-sdk-s3, s3_region is required.
# * +s3_metadata+: These key/value pairs will be stored with the
# object. This option works by prefixing each key with
# "x-amz-meta-" before sending it as a header on the object
Expand All @@ -117,20 +117,16 @@ module Storage
# :s3_storage_class => :REDUCED_REDUNDANCY
#
# Other storage classes, such as <tt>:STANDARD_IA</tt>, are also available—see the
# documentation for the <tt>aws-sdk</tt> gem for the full list.
# documentation for the <tt>aws-sdk-s3</tt> gem for the full list.

module S3
def self.extended base
begin
require 'aws-sdk-s3'
require "aws-sdk-s3"
rescue LoadError => e
e.message << " (You may need to install the aws-sdk-s3 gem)"
raise e
end
if Gem::Version.new(Aws::VERSION) >= Gem::Version.new(2) &&
Gem::Version.new(Aws::VERSION) <= Gem::Version.new("2.0.33")
raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
end

base.instance_eval do
@s3_options = @options[:s3_options] || {}
Expand Down Expand Up @@ -158,11 +154,6 @@ def self.extended base

@http_proxy = @options[:http_proxy] || nil

if @options.has_key?(:use_accelerate_endpoint) &&
Gem::Version.new(Aws::VERSION) < Gem::Version.new("2.3.0")
raise LoadError, ":use_accelerate_endpoint is only available from aws-sdk version 2.3.0. Please upgrade aws-sdk to a newer version."
end

@use_accelerate_endpoint = @options[:use_accelerate_endpoint]
end

Expand Down Expand Up @@ -251,7 +242,7 @@ def s3_interface
userinfo += ":#{http_proxy_password}" if http_proxy_password
proxy_opts[:userinfo] = userinfo
end
config[:proxy_uri] = URI::HTTP.build(proxy_opts)
config[:http_proxy] = URI::HTTP.build(proxy_opts)
end

config[:use_accelerate_endpoint] = use_accelerate_endpoint?
Expand Down
1 change: 0 additions & 1 deletion lib/paperclip/style.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
module Paperclip
# The Style class holds the definition of a thumbnail style, applying
# whatever processing is required to normalize the definition and delaying
Expand Down
1 change: 1 addition & 0 deletions lib/paperclip/url_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def for(style_name, options)
interpolated = attachment_options[:interpolator].interpolate(
most_appropriate_url, @attachment, style_name
)
return unless interpolated

escaped = escape_url_as_needed(interpolated, options)
timestamp_as_needed(escaped, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/paperclip.rake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace :paperclip do
attachment = instance.send(name)
begin
attachment.reprocess!(*styles)
rescue Exception => e
rescue StandardError => e
Paperclip::Task.log_error("exception while processing #{klass} ID #{instance.id}:")
Paperclip::Task.log_error(" " + e.message + "\n")
end
Expand Down
2 changes: 1 addition & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rspec', '~> 3.0')
s.add_development_dependency('appraisal')
s.add_development_dependency('mocha')
s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
s.add_development_dependency('aws-sdk-s3')
s.add_development_dependency('bourne')
s.add_development_dependency('cucumber-rails')
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
Expand Down
1 change: 0 additions & 1 deletion spec/paperclip/attachment_processing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'

describe 'Attachment Processing' do
Expand Down
1 change: 0 additions & 1 deletion spec/paperclip/attachment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'

describe Paperclip::Attachment do
Expand Down
1 change: 0 additions & 1 deletion spec/paperclip/filename_cleaner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'

describe Paperclip::FilenameCleaner do
Expand Down
1 change: 0 additions & 1 deletion spec/paperclip/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'
require 'open-uri'

Expand Down
Loading