diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 6587dc00b1..0c54761bc8 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -217,7 +217,13 @@ coreHelpers.content = function (options) { truncateOptions[key] = parseInt(truncateOptions[key], 10); }); - if (truncateOptions.words || truncateOptions.characters) { + if (truncateOptions.hasOwnProperty('words') || truncateOptions.hasOwnProperty('characters')) { + // Due to weirdness in downsize the 'words' option + // must be passed as a string. refer to #1796 + // TODO: when downsize fixes this quirk remove this hack. + if (truncateOptions.hasOwnProperty('words')) { + truncateOptions.words = truncateOptions.words.toString(); + } return new hbs.handlebars.SafeString( downsize(this.html, truncateOptions) ); diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 92166eeb7e..9cbcbc0f33 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -75,6 +75,34 @@ describe('Core Helpers', function () { rendered.string.should.equal("
Hello World
"); }); + it('can truncate html to 0 words', function () { + var html = "Hello World! It's me!
", + rendered = ( + helpers.content + .call( + {html: html}, + {"hash": {"words": "0"}} + ) + ); + + should.exist(rendered); + rendered.string.should.equal(""); + }); + + it('can truncate html to 0 words, leaving image tag if it is first', function () { + var html = "Hello World! It's me!
", + rendered = ( + helpers.content + .call( + {html: html}, + {"hash": {"words": "0"}} + ) + ); + + should.exist(rendered); + rendered.string.should.equal(""); + }); + it('can truncate html by character', function () { var html = "Hello World! It's me!
", rendered = (