From 551610204e5bcd898f83e64349915ea994f369d0 Mon Sep 17 00:00:00 2001 From: shanemac10 Date: Fri, 16 Aug 2019 08:26:16 -0500 Subject: [PATCH] Add fast-fails to Array library helpers Array helpers.forEach was causing errors that resulted in status 500 errors in runtime when passed undefined or null values. Added `if (!Array.isArray(array)) return '';` as a fast-fail measure to it and other Array helpers to handle bad parameters without causing errors. This fast-fail was already being used on multiple other helpers in this file, and was copied and added to those which might error without it. --- lib/array.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/array.js b/lib/array.js index 1e0fc527..c93b6624 100644 --- a/lib/array.js +++ b/lib/array.js @@ -75,6 +75,7 @@ helpers.before = function(array, n) { */ helpers.eachIndex = function(array, options) { + if (!Array.isArray(array)) return ''; var result = ''; for (var i = 0; i < array.length; i++) { result += options.fn({item: array[i], index: i}); @@ -100,6 +101,7 @@ helpers.eachIndex = function(array, options) { */ helpers.filter = function(array, value, options) { + if (!Array.isArray(array)) array = []; var content = ''; var results = []; @@ -182,6 +184,7 @@ helpers.first = function(array, n) { */ helpers.forEach = function(array, options) { + if (!Array.isArray(array)) return ''; var data = utils.createFrame(options, options.hash); var len = array.length; var buffer = '';