diff --git a/core/frontend/helpers/link_class.js b/core/frontend/helpers/link_class.js index a9f30846d3..58430a575b 100644 --- a/core/frontend/helpers/link_class.js +++ b/core/frontend/helpers/link_class.js @@ -18,7 +18,7 @@ module.exports = function link_class(options) { // eslint-disable-line camelcase // If the for attribute is present but empty, this is probably a dynamic data problem, hard for theme devs to track down // E.g. {{link_class for=slug}} in a context where slug returns an empty string // Error's here aren't useful (same as with empty get helper filters) so we fallback gracefully - if (!options.hash.for) { + if (!options.hash.for || options.hash.for.string === '') { options.hash.for = ''; } diff --git a/test/unit/helpers/link_class_spec.js b/test/unit/helpers/link_class_spec.js index e83fffff8a..a29899a39c 100644 --- a/test/unit/helpers/link_class_spec.js +++ b/test/unit/helpers/link_class_spec.js @@ -48,6 +48,12 @@ describe('{{link_class}} helper', function () { .should.eql(''); }); + it('silently accepts an empty SafeString', function () { + compile('{{link_class for=blank_safe_string}}') + .with({blank_safe_string: new handlebars.SafeString('')}) + .should.eql(''); + }); + describe('activeClass', function () { it('gets applied correctly', function () { // Test matching relative URL