Fix front-end URL output for more URL schemes

- allows direct pass-through of protocol-relative (`//host`), alternate-scheme (`tel:`), and anchor-only urls (`#contact`)
This commit is contained in:
Kevin Ansfield 2015-09-23 16:40:06 +01:00 committed by Hannah Wolfe
parent b160cd2e32
commit 621b633079
2 changed files with 8 additions and 1 deletions

View File

@ -210,7 +210,8 @@ function urlFor(context, data, absolute) {
}
// This url already has a protocol so is likely an external url to be returned
if (urlPath && (urlPath.indexOf('://') !== -1 || urlPath.indexOf('mailto:') === 0)) {
// or it is an anchor-only path
if (urlPath && (urlPath.indexOf('://') !== -1 || urlPath.match(/^(\/\/|#|[a-zA-Z0-9-]*:)/))) {
return urlPath;
}

View File

@ -151,4 +151,10 @@ describe('{{url}} helper', function () {
should.exist(rendered);
rendered.should.equal('http://casper.website/baz');
});
it('should pass through protocol-relative URLs');
it('should pass through URLs with alternative schemes');
it('should pass through anchor-only URLs');
});