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 [];
|
||||
return weblinks.filter(weblink => !this._isDirectCommit(weblink)).map(
|
||||
({name, url}) => {
|
||||
if (url.startsWith('https:') || url.startsWith('http:')) {
|
||||
return {name, url};
|
||||
} else {
|
||||
return {
|
||||
name,
|
||||
url: `../../${url}`,
|
||||
};
|
||||
if (!url.startsWith('https:') && !url.startsWith('http:')) {
|
||||
url = this.getBaseUrl() + (url.startsWith('/') ? '' : '/') + url;
|
||||
}
|
||||
return {name, url};
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -44,6 +44,23 @@ limitations under the License.
|
||||
|
||||
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', () => {
|
||||
let url = '/foo/bar';
|
||||
let hash = element._getHashFromCanonicalPath(url);
|
||||
|
Reference in New Issue
Block a user