Merge branch 'stable-2.16' into stable-3.0
* stable-2.16:
Set version to 2.16.12-SNAPSHOT
Set version to 2.16.11.1
Update git submodules
link-text-parser.js: Fix indentation
Fix base url in addHTML to correctly match
Add base url to addHTML
Add license to dark-theme
Change-Id: I6769964a0bed0d055cd38a10c8d5fcea9b0f2e70
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text_test.html b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text_test.html
index 7cc3493..e644806 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text_test.html
@@ -67,6 +67,10 @@
match: 'hash:(.+)',
html: '<a href="#/awesomesauce">$1</a>',
},
+ baseurl: {
+ match: 'test (.+)',
+ html: '<a href="/r/awesomesauce">$1</a>',
+ },
disabledconfig: {
match: 'foo:(.+)',
link: 'https://google.com/search?q=$1',
@@ -201,6 +205,24 @@
assert.equal(linkEl.textContent, 'foo');
});
+ test('html with base url', () => {
+ window.CANONICAL_PATH = '/r';
+
+ element.content = 'test foo';
+ const linkEl = element.$.output.childNodes[0];
+ assert.isTrue(linkEl.href.endsWith('/r/awesomesauce'));
+ assert.equal(linkEl.textContent, 'foo');
+ });
+
+ test('hash html with base url', () => {
+ window.CANONICAL_PATH = '/r';
+
+ element.content = 'hash:foo';
+ const linkEl = element.$.output.childNodes[0];
+ assert.isTrue(linkEl.href.endsWith('/r/awesomesauce'));
+ assert.equal(linkEl.textContent, 'foo');
+ });
+
test('disabled config', () => {
element.content = 'foo:baz';
assert.equal(element.$.output.innerHTML, 'foo:baz');
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.js b/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.js
index 5b33091..42011b2 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.js
+++ b/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.js
@@ -50,6 +50,7 @@
this.linkConfig = linkConfig;
this.callback = callback;
this.removeZeroWidthSpace = opt_removeZeroWidthSpace;
+ this.baseUrl = Gerrit.BaseUrlBehavior.getBaseUrl();
Object.preventExtensions(this);
}
@@ -141,7 +142,7 @@
htmlOutput = a;
} else if (html) {
const fragment = document.createDocumentFragment();
- // Create temporary div to hold the nodes in.
+ // Create temporary div to hold the nodes in.
const div = document.createElement('div');
div.innerHTML = html;
while (div.firstChild) {
@@ -172,10 +173,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;
- }
+ if (!!this.baseUrl && href.startsWith('/') &&
+ !href.startsWith(this.baseUrl)) {
+ href = this.baseUrl + href;
+ }
this.addItem(text, href, null, position, length, outputArray);
};
@@ -193,6 +194,10 @@
GrLinkTextParser.prototype.addHTML =
function(html, position, length, outputArray) {
if (this.hasOverlap(position, length, outputArray)) { return; }
+ if (!!this.baseUrl && html.match(/<a href=\"\//g) &&
+ !new RegExp(`^<a href="${this.baseUrl}`, 'g').test(html)) {
+ html = html.replace(/<a href=\"\//g, `<a href=\"${this.baseUrl}\/`);
+ }
this.addItem(null, null, html, position, length, outputArray);
};
diff --git a/polygerrit-ui/app/styles/themes/dark-theme.html b/polygerrit-ui/app/styles/themes/dark-theme.html
index d5db416..1b239b2 100644
--- a/polygerrit-ui/app/styles/themes/dark-theme.html
+++ b/polygerrit-ui/app/styles/themes/dark-theme.html
@@ -1,3 +1,19 @@
+<!--
+@license
+Copyright (C) 2019 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
<dom-module id="dark-theme">
<custom-style><style is="custom-style">
html {