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:
parent
6bffa893b1
commit
dc84983550
2 changed files with 9 additions and 1 deletions
|
@ -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"
|
||||
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Add table
Reference in a new issue