Merge "Fix malformed change weblinks generation" into stable-2.16

This commit is contained in:
David Pursehouse
2018-11-14 01:08:06 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 7 deletions

View File

@@ -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};
});
},

View File

@@ -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);