diff --git a/core/frontend/helpers/ghost_head.js b/core/frontend/helpers/ghost_head.js index c95eb5191a..70029a3313 100644 --- a/core/frontend/helpers/ghost_head.js +++ b/core/frontend/helpers/ghost_head.js @@ -178,7 +178,7 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase const styleTag = ``; const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/)); - if (existingScriptIndex) { + if (existingScriptIndex !== -1) { head[existingScriptIndex] = head[existingScriptIndex] + styleTag; } else { head.push(styleTag); diff --git a/test/unit/helpers/ghost_head_spec.js b/test/unit/helpers/ghost_head_spec.js index 467570c29e..4eb7244b38 100644 --- a/test/unit/helpers/ghost_head_spec.js +++ b/test/unit/helpers/ghost_head_spec.js @@ -1631,5 +1631,31 @@ describe('{{ghost_head}} helper', function () { done(); }).catch(done); }); + + it('includes style tag on templates with no context', function (done) { + const renderObject = { + post: posts[1] + }; + + const templateOptions = { + site: { + accent_color: '#123456' + } + }; + + helpers.ghost_head(testUtils.createHbsResponse({ + templateOptions, + renderObject: renderObject, + locals: { + relativeUrl: '/post/amp/', + context: null, + safeVersion: '0.3' + } + })).then(function (rendered) { + should.exist(rendered); + rendered.string.should.containEql(''); + done(); + }).catch(done); + }); }); });