From 9e92a2d4d880224e0f7a23eb2cd41b8cd526d56e Mon Sep 17 00:00:00 2001 From: Tim Schoch Date: Mon, 8 Aug 2016 11:39:46 +0200 Subject: [PATCH] only trim preceding slash of root object if it is present --- tool.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tool.js b/tool.js index 1652692..9b191ba 100644 --- a/tool.js +++ b/tool.js @@ -23,6 +23,10 @@ module.exports = function(options) { if (err) { deferred.reject(err); } else { + // trim the precedeing slash + if ( '/' == defaultRootObject.charAt( 0 ) ) { + defaultRootObject = defaultRootObject.substr(1); + } // AWS Service returns errors if we don't fix these if (data.DistributionConfig.Comment === null) data.DistributionConfig.Comment = ''; @@ -36,13 +40,13 @@ module.exports = function(options) { data.DistributionConfig.Origins.Items[0].S3OriginConfig.OriginAccessIdentity = ''; } - if (data.DistributionConfig.DefaultRootObject === defaultRootObject.substr(1)) { + if (data.DistributionConfig.DefaultRootObject === defaultRootObject) { gutil.log('gulp-cloudfront:', "DefaultRootObject hasn't changed, not updating."); return deferred.resolve(); } // Update the distribution with the new default root object (trim the precedeing slash) - data.DistributionConfig.DefaultRootObject = defaultRootObject.substr(1); + data.DistributionConfig.DefaultRootObject = defaultRootObject; cloudfront.updateDistribution({ IfMatch: data.ETag, @@ -53,7 +57,7 @@ module.exports = function(options) { if (err) { deferred.reject(err); } else { - gutil.log('gulp-cloudfront:', 'DefaultRootObject updated to [' + defaultRootObject.substr(1) + '].'); + gutil.log('gulp-cloudfront:', 'DefaultRootObject updated to [' + defaultRootObject + '].'); deferred.resolve(); }