From cbea617a248c40c580b3d48ee20ca2ee7046251b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 15 Dec 2015 13:04:06 +0000 Subject: [PATCH] Ensure `{{ghost_head}}` doesn't overwrite values closes #6221 - clones contextObject so that updating values doesn't overwrite real data --- core/server/helpers/ghost_head.js | 2 +- core/test/unit/server_helpers/ghost_head_spec.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/server/helpers/ghost_head.js b/core/server/helpers/ghost_head.js index d267d52180..0ae312f622 100644 --- a/core/server/helpers/ghost_head.js +++ b/core/server/helpers/ghost_head.js @@ -302,7 +302,7 @@ ghost_head = function (options) { schema, title = hbs.handlebars.Utils.escapeExpression(blog.title), context = self.context ? self.context[0] : null, - contextObject = self[context] || blog; + contextObject = _.cloneDeep(self[context] || blog); // Store Async calls in an object of named promises props.url = urlHelper.call(self, {hash: {absolute: true}}); diff --git a/core/test/unit/server_helpers/ghost_head_spec.js b/core/test/unit/server_helpers/ghost_head_spec.js index a1c23b96af..b19dae5fca 100644 --- a/core/test/unit/server_helpers/ghost_head_spec.js +++ b/core/test/unit/server_helpers/ghost_head_spec.js @@ -2,6 +2,7 @@ /*jshint expr:true*/ var should = require('should'), sinon = require('sinon'), + _ = require('lodash'), Promise = require('bluebird'), hbs = require('express-hbs'), utils = require('./utils'), @@ -243,7 +244,7 @@ describe('{{ghost_head}} helper', function () { image: '/content/images/test-author-image.png', cover: '/content/images/author-cover-image.png', website: 'http://authorwebsite.com' - }; + }, authorBk = _.cloneDeep(author); helpers.ghost_head.call( {safeVersion: '0.3', relativeUrl: '/author/AuthorName/', author: author, context: ['author']}, @@ -273,6 +274,8 @@ describe('{{ghost_head}} helper', function () { rendered.string.should.match(/"name": "Author name"/); rendered.string.should.match(/"description": "Author bio"/); + author.should.eql(authorBk); + done(); }).catch(done); }); @@ -331,7 +334,7 @@ describe('{{ghost_head}} helper', function () { website: 'http://authorwebsite.com', bio: 'Author bio' } - }; + }, postBk = _.cloneDeep(post); helpers.ghost_head.call( {relativeUrl: '/post/', safeVersion: '0.3', context: ['post'], post: post}, @@ -382,6 +385,8 @@ describe('{{ghost_head}} helper', function () { rendered.string.should.match(//); rendered.string.should.match(//); + post.should.eql(postBk); + done(); }).catch(done); });