Fix malformed change weblinks generation
Followup to I0d9de3a2.
Bug: Issue 5316
Change-Id: I849ab176161512130b60f2ac4775fc1f365fe426
(cherry picked from commit 5c390ad9f7
)
This commit is contained in:

committed by
Paladox none

parent
b22b8a7b12
commit
a2dc6f24d2
@@ -324,14 +324,10 @@
|
|||||||
if (!weblinks || !weblinks.length) return [];
|
if (!weblinks || !weblinks.length) return [];
|
||||||
return weblinks.filter(weblink => !this._isDirectCommit(weblink)).map(
|
return weblinks.filter(weblink => !this._isDirectCommit(weblink)).map(
|
||||||
({name, url}) => {
|
({name, url}) => {
|
||||||
if (url.startsWith('https:') || url.startsWith('http:')) {
|
if (!url.startsWith('https:') && !url.startsWith('http:')) {
|
||||||
return {name, url};
|
url = this.getBaseUrl() + (url.startsWith('/') ? '' : '/') + url;
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
url: `../../${url}`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
return {name, url};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -44,6 +44,23 @@ limitations under the License.
|
|||||||
|
|
||||||
teardown(() => { sandbox.restore(); });
|
teardown(() => { sandbox.restore(); });
|
||||||
|
|
||||||
|
test('_getChangeWeblinks', () => {
|
||||||
|
sandbox.stub(element, '_isDirectCommit').returns(false);
|
||||||
|
sandbox.stub(element, 'getBaseUrl').returns('base');
|
||||||
|
const link = {name: 'test', url: 'test/url'};
|
||||||
|
const mapLinksToConfig = weblink => ({options: {weblinks: [weblink]}});
|
||||||
|
assert.deepEqual(element._getChangeWeblinks(mapLinksToConfig(link))[0],
|
||||||
|
{name: 'test', url: 'base/test/url'});
|
||||||
|
|
||||||
|
link.url = '/' + link.url;
|
||||||
|
assert.deepEqual(element._getChangeWeblinks(mapLinksToConfig(link))[0],
|
||||||
|
{name: 'test', url: 'base/test/url'});
|
||||||
|
|
||||||
|
link.url = 'https:/' + link.url;
|
||||||
|
assert.deepEqual(element._getChangeWeblinks(mapLinksToConfig(link))[0],
|
||||||
|
{name: 'test', url: 'https://test/url'});
|
||||||
|
});
|
||||||
|
|
||||||
test('_getHashFromCanonicalPath', () => {
|
test('_getHashFromCanonicalPath', () => {
|
||||||
let url = '/foo/bar';
|
let url = '/foo/bar';
|
||||||
let hash = element._getHashFromCanonicalPath(url);
|
let hash = element._getHashFromCanonicalPath(url);
|
||||||
|
Reference in New Issue
Block a user