Preserve querystrings during redirects of legacy change URLs

Bug: Issue 4696
Change-Id: I43b37cd7958db8030d99f84b4a3e64dcc75b46db
This commit is contained in:
Ravi Mistry
2017-10-04 08:50:34 -04:00
parent 33b527faf0
commit 88d0c24b1b
2 changed files with 24 additions and 2 deletions

View File

@@ -227,10 +227,14 @@
} else if (params.view === Views.CHANGE) {
let range = this._getPatchRangeExpression(params);
if (range.length) { range = '/' + range; }
let suffix = `${range}`;
if (params.querystring) {
suffix += '?' + params.querystring;
}
if (params.project) {
url = `/c/${params.project}/+/${params.changeNum}${range}`;
url = `/c/${params.project}/+/${params.changeNum}${suffix}`;
} else {
url = `/c/${params.changeNum}${range}`;
url = `/c/${params.changeNum}${suffix}`;
}
} else if (params.view === Views.DASHBOARD) {
if (params.sections) {
@@ -988,6 +992,7 @@
basePatchNum: ctx.params[3],
patchNum: ctx.params[5],
view: Gerrit.Nav.View.CHANGE,
querystring: ctx.querystring,
};
this._normalizeLegacyRouteParams(params);

View File

@@ -237,13 +237,28 @@ limitations under the License.
changeNum: '1234',
project: 'test',
};
const paramsWithQuery = {
view: Gerrit.Nav.View.CHANGE,
changeNum: '1234',
project: 'test',
querystring: 'revert&foo=bar'
};
assert.equal(element._generateUrl(params), '/c/test/+/1234');
assert.equal(element._generateUrl(paramsWithQuery),
'/c/test/+/1234?revert&foo=bar');
params.patchNum = 10;
assert.equal(element._generateUrl(params), '/c/test/+/1234/10');
paramsWithQuery.patchNum = 10;
assert.equal(element._generateUrl(paramsWithQuery),
'/c/test/+/1234/10?revert&foo=bar');
params.basePatchNum = 5;
assert.equal(element._generateUrl(params), '/c/test/+/1234/5..10');
paramsWithQuery.basePatchNum = 5;
assert.equal(element._generateUrl(paramsWithQuery),
'/c/test/+/1234/5..10?revert&foo=bar');
});
test('diff', () => {
@@ -1103,6 +1118,7 @@ limitations under the License.
null, // 4 Unused
9, // 5 Patch number
],
querystring: '',
};
element._handleChangeLegacyRoute(ctx);
assert.isTrue(normalizeRouteStub.calledOnce);
@@ -1111,6 +1127,7 @@ limitations under the License.
basePatchNum: 6,
patchNum: 9,
view: Gerrit.Nav.View.CHANGE,
querystring: '',
});
});