0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

🐛 Returned 0 for word/image count when html is null

refs #10429
This commit is contained in:
Fabien O'Carroll 2019-01-29 13:34:48 +01:00
parent fbee79f691
commit 9fd9ad3fbb

View file

@ -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(/<img(.|\n)*?>/g) || []).length;
return html ? (html.match(/<img(.|\n)*?>/g) || []).length : 0;
};
module.exports.findKey = function findKey(key /* ...objects... */) {