Merge "Open relative commentlinks in same tab" into stable-2.16

This commit is contained in:
Sven Selberg
2020-02-21 12:12:53 +00:00
committed by Gerrit Code Review
2 changed files with 12 additions and 6 deletions

View File

@@ -68,10 +68,16 @@
this._handleParseResult.bind(this), this.removeZeroWidthSpace);
parser.parse(content);
// Ensure that links originating from HTML commentlink configs open in a
// new tab. @see Issue 5567
// Ensure that external links originating from HTML commentlink configs
// open in a new tab. @see Issue 5567
// Ensure links to the same host originating from commentlink configs
// open in the same tab. @see Issue 4616
output.querySelectorAll('a').forEach(anchor => {
anchor.setAttribute('target', '_blank');
if (anchor.hostname === window.location.hostname) {
anchor.setAttribute('target', '_self');
} else {
anchor.setAttribute('target', '_blank');
}
anchor.setAttribute('rel', 'noopener');
});
},

View File

@@ -142,7 +142,7 @@ limitations under the License.
const linkEl = element.$.output.childNodes[1];
assert.equal(textNode.textContent, prefix);
const url = '/q/' + changeID;
assert.equal(linkEl.target, '_blank');
assert.equal(linkEl.target, '_self');
// Since url is a path, the host is added automatically.
assert.isTrue(linkEl.href.endsWith(url));
assert.equal(linkEl.textContent, changeID);
@@ -160,7 +160,7 @@ limitations under the License.
const linkEl = element.$.output.childNodes[1];
assert.equal(textNode.textContent, prefix);
const url = '/r/q/' + changeID;
assert.equal(linkEl.target, '_blank');
assert.equal(linkEl.target, '_self');
// Since url is a path, the host is added automatically.
assert.isTrue(linkEl.href.endsWith(url));
assert.equal(linkEl.textContent, changeID);
@@ -201,7 +201,7 @@ limitations under the License.
assert.equal(textNode.textContent, prefix);
assert.equal(changeLinkEl.target, '_blank');
assert.equal(changeLinkEl.target, '_self');
assert.isTrue(changeLinkEl.href.endsWith(changeUrl));
assert.equal(changeLinkEl.textContent, changeID);