🐛 Fixed 404 errors if navigation URLs are somehow blank

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
This commit is contained in:
Kevin Ansfield 2021-03-24 09:43:43 +00:00
parent e290983042
commit bc63f51fd7
2 changed files with 7 additions and 1 deletions

View File

@ -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 = '';
}

View File

@ -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