Encode repo names when generating URLs

Bug: Issue 9598
Change-Id: If87ce3564d4726bea0756bf8934e5e4c2ac9fe04
This commit is contained in:
Wyatt Allen
2018-09-12 17:13:12 -07:00
parent e171a310ae
commit c703285bc3
2 changed files with 26 additions and 2 deletions

View File

@@ -396,7 +396,8 @@
suffix += ',edit';
}
if (params.project) {
return `/c/${params.project}/+/${params.changeNum}${suffix}`;
const encodedProject = this.encodeURL(params.project, true);
return `/c/${encodedProject}/+/${params.changeNum}${suffix}`;
} else {
return `/c/${params.changeNum}${suffix}`;
}
@@ -462,7 +463,8 @@
}
if (params.project) {
return `/c/${params.project}/+/${params.changeNum}${suffix}`;
const encodedProject = this.encodeURL(params.project, true);
return `/c/${encodedProject}/+/${params.changeNum}${suffix}`;
} else {
return `/c/${params.changeNum}${suffix}`;
}

View File

@@ -283,6 +283,16 @@ limitations under the License.
'/c/test/+/1234/5..10?revert&foo=bar');
});
test('change with repo name encoding', () => {
const params = {
view: Gerrit.Nav.View.CHANGE,
changeNum: '1234',
project: 'x+/y+/z+/w',
};
assert.equal(element._generateUrl(params),
'/c/x%252B/y%252B/z%252B/w/+/1234');
});
test('diff', () => {
const params = {
view: Gerrit.Nav.View.DIFF,
@@ -317,6 +327,18 @@ limitations under the License.
'/c/test/+/42/2/file.cpp#b123');
});
test('diff with repo name encoding', () => {
const params = {
view: Gerrit.Nav.View.DIFF,
changeNum: '42',
path: 'x+y/path.cpp',
patchNum: 12,
project: 'x+/y',
};
assert.equal(element._generateUrl(params),
'/c/x%252B/y/+/42/12/x%252By/path.cpp');
});
test('edit', () => {
const params = {
view: Gerrit.Nav.View.EDIT,