Use regex for query route pattern

Query URLs in GWT permitted un-encoded slashes in project operators,
however the route pattern for queries in PolyGerrit used the string
style of definition which would not permit slashes in params. With this
change, the two patterns for searches are unified into a single regex
style of definition which permits such slashes.

Bug: Issue 7306
Change-Id: I597d9f0f3d1cb747998bb4213e21a663944f9ce6
This commit is contained in:
Wyatt Allen
2017-10-06 15:54:19 +01:00
parent c6b0329aad
commit 61ebb6ca44
2 changed files with 22 additions and 5 deletions

View File

@@ -87,8 +87,7 @@
PLUGIN_LIST_FILTER: '/admin/plugins/q/filter::filter',
PLUGIN_LIST_FILTER_OFFSET: '/admin/plugins/q/filter::filter,:offset',
QUERY: '/q/:query',
QUERY_OFFSET: '/q/:query,:offset',
QUERY: /^\/q\/([^,]+)(,(\d+))?$/,
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>][/].
CHANGE_LEGACY: /^\/c\/(\d+)\/?(((-?\d+|edit)(\.\.(\d+|edit))?))?\/?$/,
@@ -546,7 +545,6 @@
this._mapRoute(RoutePattern.ADMIN_PLACEHOLDER,
'_handleAdminPlaceholderRoute', true);
this._mapRoute(RoutePattern.QUERY_OFFSET, '_handleQueryRoute');
this._mapRoute(RoutePattern.QUERY, '_handleQueryRoute');
this._mapRoute(RoutePattern.CHANGE_NUMBER_LEGACY,
@@ -953,8 +951,11 @@
},
_handleQueryRoute(data) {
data.params.view = Gerrit.Nav.View.SEARCH;
this._setParams(data.params);
this._setParams({
view: Gerrit.Nav.View.SEARCH,
query: data.params[0],
offset: data.params[2],
});
},
_handleChangeNumberLegacyRoute(ctx) {

View File

@@ -546,6 +546,22 @@ limitations under the License.
'/c/test/+/42#foo');
});
test('_handleQueryRoute', () => {
const data = {params: ['project:foo/bar/baz']};
assertDataToParams(data, '_handleQueryRoute', {
view: Gerrit.Nav.View.SEARCH,
query: 'project:foo/bar/baz',
offset: undefined,
});
data.params.push(',123', '123');
assertDataToParams(data, '_handleQueryRoute', {
view: Gerrit.Nav.View.SEARCH,
query: 'project:foo/bar/baz',
offset: '123',
});
});
suite('_handleRegisterRoute', () => {
test('happy path', () => {
const ctx = {params: ['/foo/bar']};