Merge "Handle and redirect project-based URLs"
This commit is contained in:
@@ -308,6 +308,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Matches
|
||||||
|
// /c/<project>/+/<changeNum>/[<basePatchNum>..][<patchNum>]/[path].
|
||||||
|
// TODO(kaspern): Migrate completely to project based URLs, with backwards
|
||||||
|
// compatibility for change-only.
|
||||||
|
page(/^\/c\/([^\/]+)\/\+\/(\d+)(\/?((\d+)(\.\.(\d+))?(\/(.+))?))?\/?$/,
|
||||||
|
ctx => {
|
||||||
|
// Parameter order is based on the regex group number matched.
|
||||||
|
const params = {
|
||||||
|
project: ctx.params[0],
|
||||||
|
changeNum: ctx.params[1],
|
||||||
|
basePatchNum: ctx.params[4],
|
||||||
|
patchNum: ctx.params[6],
|
||||||
|
path: ctx.params[8],
|
||||||
|
view: ctx.params[8] ? 'gr-diff-view' : 'gr-change-view',
|
||||||
|
};
|
||||||
|
// TODO(kaspern): This should be generated via generateURL.
|
||||||
|
// Making that happen requires an unfortunate amount of refactoring,
|
||||||
|
// as the schema for app.params differs from the schema of the params
|
||||||
|
// object passed to generateUrl in several ways.
|
||||||
|
let url = `/c/${encodeURIComponent(params.changeNum)}/`;
|
||||||
|
if (params.basePatchNum) {
|
||||||
|
url += `${encodeURIComponent(params.basePatchNum)}`;
|
||||||
|
if (params.patchNum) {
|
||||||
|
url += `..${encodeURIComponent(params.patchNum)}`;
|
||||||
|
}
|
||||||
|
if (params.path) {
|
||||||
|
url += `/${encode(params.path, true)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
history.replaceState(null, null, url);
|
||||||
|
normalizePatchRangeParams(params);
|
||||||
|
app.params = params;
|
||||||
|
});
|
||||||
|
|
||||||
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>].
|
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>].
|
||||||
page(/^\/c\/(\d+)\/?(((\d+)(\.\.(\d+))?))?$/, ctx => {
|
page(/^\/c\/(\d+)\/?(((\d+)(\.\.(\d+))?))?$/, ctx => {
|
||||||
// Parameter order is based on the regex group number matched.
|
// Parameter order is based on the regex group number matched.
|
||||||
@@ -347,17 +381,12 @@
|
|||||||
// TODO(kaspern): Utilize gr-url-encoding-behavior.html when the router
|
// TODO(kaspern): Utilize gr-url-encoding-behavior.html when the router
|
||||||
// is replaced with a Polymer counterpart.
|
// is replaced with a Polymer counterpart.
|
||||||
// @see Issue 4255 regarding double-encoding.
|
// @see Issue 4255 regarding double-encoding.
|
||||||
let path = encodeURIComponent(encodeURIComponent(params.path));
|
|
||||||
// @see Issue 4577 regarding more readable URLs.
|
|
||||||
path = path.replace(/%252F/g, '/');
|
|
||||||
path = path.replace(/%2520/g, '+');
|
|
||||||
|
|
||||||
page.redirect('/c/' +
|
page.redirect('/c/' +
|
||||||
encodeURIComponent(params.changeNum) +
|
encodeURIComponent(params.changeNum) +
|
||||||
'/' +
|
'/' +
|
||||||
encodeURIComponent(params.patchNum) +
|
encodeURIComponent(params.patchNum) +
|
||||||
'/' +
|
'/' +
|
||||||
path);
|
encode(params.path, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user