Permalink
Browse files

Encode file paths before sending them to CloudFront

  • Loading branch information...
1 parent 4b0f439 commit 55397d22a711fd93c9707c00f9c915e5be4ecb17 @laurilehmijoki committed Mar 4, 2014
Showing with 39 additions and 17 deletions.
  1. +4 −0 changelog.md
  2. +8 −1 lib/cloudfront/invalidator.rb
  3. +1 −1 s3_website.gemspec
  4. +26 −15 spec/lib/cloudfront/invalidator_spec.rb
View
@@ -2,6 +2,10 @@
This project uses [Semantic Versioning](http://semver.org).
+## 1.6.12
+
+* Fix bug <https://github.com/laurilehmijoki/s3_website/issues/63>
+
## 1.6.11
* Loosen the dependency spec of mime-types (#70)
@@ -9,13 +9,20 @@ def self.invalidate(config, changed_files)
s3_object_keys << ""
report = SimpleCloudfrontInvalidator::CloudfrontClient.new(
aws_key, aws_secret, cloudfront_distribution_id
- ).invalidate(s3_object_keys)
+ ).invalidate(url_encode_keys s3_object_keys)
puts report[:text_report]
report[:invalidated_items_count]
end
private
+ def self.url_encode_keys(keys)
+ require 'uri'
+ keys.map do |key|
+ URI::encode(key, Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@', "'"]))
+ end
+ end
+
def self.apply_config(config, changed_files)
if config['cloudfront_invalidate_root']
changed_files.map { |changed_file|
View
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "s3_website"
- s.version = "1.6.11"
+ s.version = "1.6.12"
s.platform = Gem::Platform::RUBY
s.authors = ["Lauri Lehmijoki"]
s.email = ["lauri.lehmijoki@iki.fi"]
@@ -1,13 +1,13 @@
require 'spec_helper'
describe S3Website::Cloudfront::Invalidator do
- describe 'default behaviour' do
- let(:config) {{
- 's3_id' => 'aws id',
- 's3_secret' => 'aws secret',
- 'cloudfront_distribution_id' => 'EFXX'
- }}
+ let(:config) {{
+ 's3_id' => 'aws id',
+ 's3_secret' => 'aws secret',
+ 'cloudfront_distribution_id' => 'EFXX'
+ }}
+ describe 'default behaviour' do
it 'invalidates the root resource' do
invalidator = create_simple_cloudfront_invalidator(config)
invalidator.
@@ -19,22 +19,33 @@
end
end
- describe 'option cloudfront_invalidate_root = true' do
- let(:config) {{
- 's3_id' => 'aws id',
- 's3_secret' => 'aws secret',
- 'cloudfront_distribution_id' => 'EFXX',
- 'cloudfront_invalidate_root' => true
- }}
+ context 'option cloudfront_invalidate_root = true' do
+ let(:config_with_root_invalidation) {
+ config.merge( {
+ 'cloudfront_invalidate_root' => true
+ })
+ }
it 'invalidates all root resources' do
- invalidator = create_simple_cloudfront_invalidator(config)
+ invalidator = create_simple_cloudfront_invalidator(config_with_root_invalidation)
invalidator.
should_receive(:invalidate).
with(['article/', '']).
and_return(:text_report => 'report txt')
- S3Website::Cloudfront::Invalidator.invalidate(config, ['article/index.html'])
+ S3Website::Cloudfront::Invalidator.invalidate(config_with_root_invalidation, ['article/index.html'])
+ end
+ end
+
+ context 'the file name contains special characters' do
+ it 'encodes the file paths according to rfc1738' do
+ invalidator = create_simple_cloudfront_invalidator config
+ invalidator.
+ should_receive(:invalidate).
+ with(['article/arnold%27s%20file.html', '']).
+ and_return(:text_report => 'report txt')
+
+ S3Website::Cloudfront::Invalidator.invalidate(config, ["article/arnold's file.html"])
end
end

0 comments on commit 55397d2

Please sign in to comment.