Skip to content
Browse files

Merge pull request #809 from DouweM/s3-subdomain

Also use AWS S3 subdomain URL when directory name contains a period.
  • Loading branch information...
2 parents 3755e1e + af1a2d3 commit 56592f35afc3b975b45794ca30ce2dd5c19542aa @thiagofm thiagofm committed
Showing with 15 additions and 1 deletion.
  1. +1 −1 lib/carrierwave/storage/fog.rb
  2. +14 −0 spec/storage/fog_helper.rb
View
2 lib/carrierwave/storage/fog.rb
@@ -286,7 +286,7 @@ def public_url
case @uploader.fog_credentials[:provider]
when 'AWS'
# if directory is a valid subdomain, use that style for access
- if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
+ if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
"https://#{@uploader.fog_directory}.s3.amazonaws.com/#{path}"
else
# directory is not a valid subdomain, so use path style for access
View
14 spec/storage/fog_helper.rb
@@ -69,6 +69,20 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
@fog_file.url.should_not be_nil
end
end
+
+ it "should use a subdomain URL for AWS if the directory is a valid subdomain" do
+ if @provider == 'AWS'
+ @uploader.stub(:fog_directory).and_return('assets.site.com')
+ @fog_file.public_url.should include('https://assets.site.com.s3.amazonaws.com')
+ end
+ end
+
+ it "should not use a subdomain URL for AWS if the directory is not a valid subdomain" do
+ if @provider == 'AWS'
+ @uploader.stub(:fog_directory).and_return('SiteAssets')
+ @fog_file.public_url.should include('https://s3.amazonaws.com/SiteAssets')
+ end
+ end
end
context "with asset_host" do

0 comments on commit 56592f3

Please sign in to comment.
Something went wrong with that request. Please try again.