Merge "Do not fail if user provides a too high/low label value in query"
This commit is contained in:
@@ -106,6 +106,10 @@ public final class RangeUtil {
|
||||
break;
|
||||
}
|
||||
|
||||
// Ensure that minValue <= min/max <= maxValue.
|
||||
min = Ints.constrainToRange(min, minValue, maxValue);
|
||||
max = Ints.constrainToRange(max, minValue, maxValue);
|
||||
|
||||
return new Range(prefix, min, max);
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -182,6 +183,18 @@ public class QueryChangeIT extends AbstractDaemonTest {
|
||||
.containsExactly(changeId3, changeId4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingOutOfRangeLabelValuesDoesNotCauseError() throws Exception {
|
||||
for (String operator : ImmutableList.of("=", ">", ">=", "<", "<=")) {
|
||||
QueryChanges queryChanges = queryChangesProvider.get();
|
||||
queryChanges.addQuery("label:Code-Review" + operator + "10");
|
||||
queryChanges.addQuery("label:Code-Review" + operator + "-10");
|
||||
queryChanges.addQuery("Code-Review" + operator + "10");
|
||||
queryChanges.addQuery("Code-Review" + operator + "-10");
|
||||
assertThat(queryChanges.apply(TopLevelResource.INSTANCE).statusCode()).isEqualTo(SC_OK);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertNoChangeHasMoreChangesSet(List<ChangeInfo> results) {
|
||||
for (ChangeInfo info : results) {
|
||||
assertThat(info._moreChanges).isNull();
|
||||
|
34
javatests/com/google/gerrit/index/query/RangeUtilTest.java
Normal file
34
javatests/com/google/gerrit/index/query/RangeUtilTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2019 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.index.query;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.index.query.RangeUtil.Range;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RangeUtilTest {
|
||||
@Test
|
||||
public void getRangeForValueOutsideOfMinMaxRange_minNotGreaterThanMax() {
|
||||
for (String operator : ImmutableList.of("=", ">", ">=", "<", "<=")) {
|
||||
Range range = RangeUtil.getRange("foo", operator, 10, -4, 4);
|
||||
assertThat(range.min).isAtMost(range.max);
|
||||
|
||||
range = RangeUtil.getRange("foo", operator, -10, -4, 4);
|
||||
assertThat(range.min).isAtMost(range.max);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user