From fc28deea53649c92c795d0ad833dafc64f6d6433 Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Thu, 2 Jul 2015 15:08:11 +0100 Subject: [PATCH] Added logging and error for when plugin structure is incorrect This patch is to handle circumstances where an uploaded zip file has an unexpected folder structure. --- plugins/content/bower/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/content/bower/index.js b/plugins/content/bower/index.js index 04c9bb6491..9314a7226e 100644 --- a/plugins/content/bower/index.js +++ b/plugins/content/bower/index.js @@ -837,7 +837,17 @@ function handleUploadedPlugin (req, res, next) { // first entry should be our target directory var packageJson; - var canonicalDir = path.join(outputPath, files[0]); + var canonicalDir; + + if (files.indexOf("bower.json") != -1) { + // We're at the root level so the zip file is in the expected format + canonicalDir = outputPath + } + else { + logger.log('error', 'Received plugin zip file with unexpected folder structure'); + return next(new Error('Cannot find expected bower.json file in the plugin root, please check the structure of your zip file and try again.')); + } + try { packageJson = require(path.join(canonicalDir, 'bower.json')); } catch (error) {