From bc63f51fd784ca1b53387f97dd043a9f5301aacd Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 24 Mar 2021 09:43:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20404=20errors=20if=20navi?= =?UTF-8?q?gation=20URLs=20are=20somehow=20blank?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - in very rare circumstances it's possible that a navigation url in settings can be blank, we should not throw errors in this case as it appears as a theme/routing problem which is difficult to diagnose and much worse than simply not outputting a link class --- core/frontend/helpers/link_class.js | 2 +- test/unit/helpers/link_class_spec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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