Merge "Use base url for commentlink" into stable-2.15

This commit is contained in:
Ben Rohlfs
2019-08-27 07:12:54 +00:00
committed by Gerrit Code Review
3 changed files with 24 additions and 0 deletions

View File

@@ -15,7 +15,9 @@ limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<script src="ba-linkify.js"></script>
<script src="link-text-parser.js"></script>

View File

@@ -122,6 +122,24 @@ limitations under the License.
assert.equal(linkEl.textContent, changeID);
});
test('Change-Id pattern was parsed and linked with base url', function() {
window.CANONICAL_PATH = '/r';
// "Change-Id:" pattern.
const changeID = 'I11d6a37f5e9b5df0486f6c922d8836dfa780e03e';
const prefix = 'Change-Id: ';
element.content = prefix + changeID;
const textNode = element.$.output.childNodes[0];
const linkEl = element.$.output.childNodes[1];
assert.equal(textNode.textContent, prefix);
const url = '/r/q/' + changeID;
assert.equal(linkEl.target, '_blank');
// Since url is a path, the host is added automatically.
assert.isTrue(linkEl.href.endsWith(url));
assert.equal(linkEl.textContent, changeID);
});
test('Multiple matches', function() {
element.content = 'Issue 3650\nIssue 3450';
var linkEl1 = element.$.output.childNodes[0];

View File

@@ -96,6 +96,10 @@ GrLinkTextParser.prototype.addLink =
return;
}
if (!this.hasOverlap(position, length, outputArray)) {
const baseUrl = Gerrit.BaseUrlBehavior.getBaseUrl();
if (!!baseUrl && href.startsWith('/') && !href.startsWith(baseUrl)) {
href = baseUrl + href;
}
this.addItem(text, href, null, position, length, outputArray);
}
};