From 9fd9ad3fbbc2bc75fd05c8da258573267424cfd0 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Tue, 29 Jan 2019 13:34:48 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Returned=200=20for=20word/image?= =?UTF-8?q?=20count=20when=20html=20is=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #10429 --- core/server/helpers/utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/server/helpers/utils.js b/core/server/helpers/utils.js index c6854a4365..fc4c6fd14b 100644 --- a/core/server/helpers/utils.js +++ b/core/server/helpers/utils.js @@ -9,6 +9,9 @@ const _ = require('lodash'); * with extra diacritics character matching. **/ module.exports.wordCount = function wordCount(html) { + if (!html) { + return 0; + } html = html.replace(/<(.|\n)*?>/g, ' '); // strip tags const pattern = /[a-zA-ZÀ-ÿ0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g; @@ -34,7 +37,7 @@ module.exports.wordCount = function wordCount(html) { * @description Takes an HTML string and returns the number of images **/ module.exports.imageCount = function wordCount(html) { - return (html.match(//g) || []).length; + return html ? (html.match(//g) || []).length : 0; }; module.exports.findKey = function findKey(key /* ...objects... */) {