From 8f935fe8aeec9698dfb6363b897a67c48019ed99 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 26 Mar 2020 16:38:30 +0000 Subject: [PATCH] Fixed Slack service throwing error when post is empty fixes #11694 - if the post contained no body, the `.replace` would throw an error - converted to an if-statement instead of doing `|| ''` because there would be a floating full-stop --- core/server/services/slack.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/server/services/slack.js b/core/server/services/slack.js index 277edb7beb..cfa0e17df0 100644 --- a/core/server/services/slack.js +++ b/core/server/services/slack.js @@ -28,6 +28,7 @@ function ping(post) { let message, title, author, + description, slackData = {}, slackSettings = getSlackSettings(), blogTitle = settingsCache.get('title'); @@ -37,6 +38,14 @@ function ping(post) { message = urlService.getUrlByResourceId(post.id, {absolute: true}); title = post.title ? post.title : null; author = post.authors ? post.authors[0] : null; + + if (post.custom_excerpt) { + description = post.custom_excerpt; + } else if (post.html) { + description = `${post.html.replace(/<[^>]+>/g, '').split('.').slice(0, 3).join('.')}.` + } else { + description = null; + } } else { message = post.message; } @@ -77,7 +86,7 @@ function ping(post) { fields: [ { title: 'Description', - value: post.custom_excerpt ? post.custom_excerpt : `${post.html.replace(/<[^>]+>/g, '').split('.').slice(0, 3).join('.')}.`, + value: description, short: false } ]