From 5a7356de5bc66b4445196b63c7a59a3a6e2fd4f6 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 4 Mar 2019 14:30:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20`excerpt`=20property=20b?= =?UTF-8?q?eing=20missing=20if=20`plaintext`=20is=20NULL=20or=20""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/10558 - added conditional to explicitly set `excerpt` to `null` in the API output serializer when a post has no `plaintext` or `custom_excerpt` value --- .../v2/utils/serializers/output/utils/extra-attrs.js | 2 ++ .../serializers/output/utils/extra-attrs_spec.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/core/server/api/v2/utils/serializers/output/utils/extra-attrs.js b/core/server/api/v2/utils/serializers/output/utils/extra-attrs.js index 8f6fb7c1bf..5f3ace9fba 100644 --- a/core/server/api/v2/utils/serializers/output/utils/extra-attrs.js +++ b/core/server/api/v2/utils/serializers/output/utils/extra-attrs.js @@ -8,6 +8,8 @@ module.exports.forPost = (frame, model, attrs) => { if (plaintext) { attrs.excerpt = plaintext.substring(0, 500); + } else { + attrs.excerpt = null; } } else { attrs.excerpt = attrs.custom_excerpt; diff --git a/core/test/unit/api/v2/utils/serializers/output/utils/extra-attrs_spec.js b/core/test/unit/api/v2/utils/serializers/output/utils/extra-attrs_spec.js index 439813bd49..78ea08afb3 100644 --- a/core/test/unit/api/v2/utils/serializers/output/utils/extra-attrs_spec.js +++ b/core/test/unit/api/v2/utils/serializers/output/utils/extra-attrs_spec.js @@ -33,5 +33,17 @@ describe('Unit: v2/utils/serializers/output/utils/extra-attrs', () => { attrs.excerpt.should.eql(new Array(501).join('A')); }); + + it('has excerpt when plaintext is null', () => { + model.get.withArgs('plaintext').returns(null); + + const attrs = {}; + + extraAttrsUtil.forPost(frame, model, attrs); + model.get.called.should.be.true(); + + attrs.should.have.property('excerpt'); + (attrs.excerpt === null).should.be.true(); + }); }); });