diff --git a/core/frontend/helpers/url.js b/core/frontend/helpers/url.js index 36fa631e8f..c531da180f 100644 --- a/core/frontend/helpers/url.js +++ b/core/frontend/helpers/url.js @@ -11,7 +11,12 @@ module.exports = function url(options) { const absolute = options && options.hash.absolute && options.hash.absolute !== 'false'; let outputUrl = getMetaDataUrl(this, absolute); - outputUrl = encodeURI(decodeURI(outputUrl)); + try { + outputUrl = encodeURI(decodeURI(outputUrl)); + } catch (err) { + // Happens when the outputURL contains an invalid URI character like "%%" or "%80" + return new SafeString(''); + } return new SafeString(outputUrl); }; diff --git a/test/unit/helpers/url_spec.js b/test/unit/helpers/url_spec.js index 66fd4a7491..db6de6e393 100644 --- a/test/unit/helpers/url_spec.js +++ b/test/unit/helpers/url_spec.js @@ -268,6 +268,12 @@ describe('{{url}} helper', function () { should.exist(rendered); rendered.string.should.equal('/?foo=space%20bar'); }); + + it('should an empty string when we can\'t parse a string', function () { + rendered = helpers.url.call({url: '/?foo=space%%bar', label: 'Baz', slug: 'baz', current: true}); + should.exist(rendered); + rendered.string.should.equal(''); + }); }); describe('with subdir', function () {