From 8e3ddcbdccea66ce611ed3ab8b182aadc319ec18 Mon Sep 17 00:00:00 2001 From: jamesbloomer Date: Tue, 24 Sep 2013 22:29:17 +0100 Subject: [PATCH] Trim version number to major and minor numbers only in meta tag closes #880 - as the version number is under control from package.json use regex to trim --- core/server/helpers/index.js | 7 +++++-- core/test/unit/server_helpers_index_spec.js | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index df3b9144e5..8a9569f613 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -208,8 +208,11 @@ coreHelpers = function (ghost) { }); ghost.registerThemeHelper('ghost_head', function (options) { - var head = []; - head.push(''); + var head = [], + majorMinor = /^(\d+\.)?(\d+)/, + trimmedVersion = this.version.match(majorMinor)[0]; + + head.push(''); head.push(''); return ghost.doFilter('ghost_head', head, function (head) { diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 567e335db2..5499f30c4a 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -189,10 +189,16 @@ describe('Core Helpers', function () { }); it('returns meta tag string', function () { - var rendered = handlebars.helpers.ghost_head.call({version: "0.3"}); + var rendered = handlebars.helpers.ghost_head.call({version: "0.3.0"}); should.exist(rendered); rendered.string.should.equal('\n'); }); + + it('returns meta tag string even if version is invalid', function () { + var rendered = handlebars.helpers.ghost_head.call({version: "0.9"}); + should.exist(rendered); + rendered.string.should.equal('\n'); + }); }); describe('ghost_foot Helper', function () {