diff --git a/ghost/core/core/frontend/helpers/url.js b/ghost/core/core/frontend/helpers/url.js index df62bd954b..c99213f4a0 100644 --- a/ghost/core/core/frontend/helpers/url.js +++ b/ghost/core/core/frontend/helpers/url.js @@ -17,7 +17,7 @@ module.exports = function url(options) { let outputUrl = getMetaDataUrl(this, absolute); try { - outputUrl = encodeURI(decodeURI(outputUrl)); + outputUrl = encodeURI(decodeURI(outputUrl)).replace(/%5B/g, '[').replace(/%5D/g, ']'); } catch (err) { // Happens when the outputURL contains an invalid URI character like "%%" or "%80" diff --git a/ghost/core/test/unit/frontend/helpers/url.test.js b/ghost/core/test/unit/frontend/helpers/url.test.js index e17700f531..97cf8d505d 100644 --- a/ghost/core/test/unit/frontend/helpers/url.test.js +++ b/ghost/core/test/unit/frontend/helpers/url.test.js @@ -225,6 +225,14 @@ describe('{{url}} helper', function () { should.exist(rendered); rendered.string.should.equal(''); }); + + it('should not encode square brackets (as in valid IPV6 addresses)', function () { + rendered = url.call( + {url: 'http://[ffff::]:2368/baz', label: 'Baz', slug: 'baz', current: true}, + {hash: {absolute: 'true'}}); + should.exist(rendered); + rendered.string.should.equal('http://[ffff::]:2368/baz'); + }); }); describe('with subdir', function () {