0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🐛 Fixed square brackets being % encoded in URLs (#14977)

fixes: #14863
refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI#encoding_for_ipv6

- added a simple Regex replace for the percent-encoded square brackets to get them back to non-encoded
- a preferred solution might be using new URL(), but that causes other issues. The regex solves the immediate need.
This commit is contained in:
rw4nn 2022-09-08 13:09:40 +02:00 committed by GitHub
parent 6bffa893b1
commit dc84983550
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

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

View file

@ -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 () {