Merge "Use base url for commentlink"

This commit is contained in:
Paladox none
2019-08-26 14:18:18 +00:00
committed by Gerrit Code Review
3 changed files with 24 additions and 1 deletions

View File

@@ -16,8 +16,9 @@ limitations under the License.
-->
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.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="/bower_components/ba-linkify/ba-linkify.js"></script>
<script src="link-text-parser.js"></script>

View File

@@ -126,6 +126,24 @@ limitations under the License.
assert.equal(linkEl.textContent, changeID);
});
test('Change-Id pattern was parsed and linked with base url', () => {
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', () => {
element.content = 'Issue 3650\nIssue 3450';
const linkEl1 = element.$.output.childNodes[0];

View File

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