From 7244266174ab8b82e61007bb7cec337ec7399d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 12 Nov 2014 17:08:11 +0100 Subject: [PATCH] FIX: support for underscores in URLs (when using S3 storage) --- Gemfile | 4 ++++ Gemfile.lock | 1 + config/locales/server.en.yml | 2 +- lib/file_helper.rb | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 590eb13a924..d7b155bc07f 100644 --- a/Gemfile +++ b/Gemfile @@ -249,6 +249,10 @@ gem 'stringex', require: false gem 'logster' +# we need that to support underscore in URLs (mostly when using S3 for storing files) +# cf. http://stackoverflow.com/a/17108137/11983 +gem 'addressable' + # perftools only works on 1.9 atm group :profile do # travis refuses to install this, instead of fuffing, just avoid it for now diff --git a/Gemfile.lock b/Gemfile.lock index 61e823047ae..775156630d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -407,6 +407,7 @@ PLATFORMS DEPENDENCIES actionpack-action_caching active_model_serializers (~> 0.8.0) + addressable annotate barber better_errors diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 1a6fa7c1f21..f6add340c75 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -847,7 +847,7 @@ en: purge_inactive_users_grace_period_days: "Grace period (in days) before a user who has not activated their account is deleted." enable_s3_uploads: "Place uploads on Amazon S3 storage. IMPORTANT: requires valid S3 credentials (both access key id & secret access key)." s3_use_iam_profile: 'Use AWS EC2 IAM role to retrieve keys. NOTE: enabling will override "s3 access key id" and "s3 secret access key" settings.' - s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase, no periods." + s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase, no periods, no underscores." s3_access_key_id: "The Amazon S3 access key id that will be used to upload images." s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images." s3_region: "The Amazon S3 region name that will be used to upload images." diff --git a/lib/file_helper.rb b/lib/file_helper.rb index af88fc0edf5..b6029f1f324 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -1,4 +1,15 @@ require "open-uri" +require "addressable/uri" + +class URI::Parser + + # HACK to support underscores in URLs + def split(url) + a = Addressable::URI::parse(url) + [a.scheme, a.userinfo, a.host, a.port, nil, a.path, nil, a.query, a.fragment] + end + +end class FileHelper