Set rel="external" on "Switch Account" links

When the switch account URL is configured with the same domain as the
app, following the link is captured by the PG catchall route. With this
change the link is always marked with rel="external" so that it will be
disregarded by page.js.

Bug: Issue 7158
Change-Id: I584a5e335935815d70fe4d5205b6c0548a52b340
This commit is contained in:
Wyatt Allen
2017-09-06 12:12:55 -07:00
parent 059fc3e96c
commit 4c13c2e13f
4 changed files with 29 additions and 10 deletions

View File

@@ -66,7 +66,7 @@
if (switchAccountUrl) {
const replacements = {path};
const url = this._interpolateUrl(switchAccountUrl, replacements);
links.push({name: 'Switch account', url});
links.push({name: 'Switch account', url, external: true});
}
links.push({name: 'Sign out', url: '/logout'});
return links;

View File

@@ -83,14 +83,20 @@ limitations under the License.
// Unparameterized switch account link.
let links = element._getLinks('/switch-account');
assert.equal(links.length, 3);
assert.deepEqual(links[1],
{name: 'Switch account', url: '/switch-account'});
assert.deepEqual(links[1], {
name: 'Switch account',
url: '/switch-account',
external: true,
});
// Parameterized switch account link.
links = element._getLinks('/switch-account${path}', '/c/123');
assert.equal(links.length, 3);
assert.deepEqual(links[1],
{name: 'Switch account', url: '/switch-account/c/123'});
assert.deepEqual(links[1], {
name: 'Switch account',
url: '/switch-account/c/123',
external: true,
});
});
test('_interpolateUrl', () => {

View File

@@ -14,6 +14,9 @@
(function() {
'use strict';
const REL_NOOPENER = 'noopener';
const REL_EXTERNAL = 'external';
Polymer({
is: 'gr-dropdown',
@@ -168,7 +171,10 @@
},
_computeLinkRel(link) {
return link.target ? 'noopener' : null;
// Note: noopener takes precedence over external.
if (link.target) { return REL_NOOPENER; }
if (link.external) { return REL_EXTERNAL; }
return null;
},
_handleItemTap(e) {

View File

@@ -72,10 +72,17 @@ limitations under the License.
});
test('link rel', () => {
assert.isNull(element._computeLinkRel({url: '/test'}));
assert.equal(
element._computeLinkRel({url: '/test', target: '_blank'}),
'noopener');
let link = {url: '/test'};
assert.isNull(element._computeLinkRel(link));
link = {url: '/test', target: '_blank'};
assert.equal(element._computeLinkRel(link), 'noopener');
link = {url: '/test', external: true};
assert.equal(element._computeLinkRel(link), 'external');
link = {url: '/test', target: '_blank', external: true};
assert.equal(element._computeLinkRel(link), 'noopener');
});
test('_getClassIfBold', () => {