remove useless path suffix

This commit is contained in:
Mengyi Zhou 2017-01-13 12:04:55 +08:00
parent 135085e25c
commit f9d2a69e63
2 changed files with 10 additions and 18 deletions

View file

@ -14,7 +14,7 @@ import java.util.*;
@Service("pathValidator") @Service("pathValidator")
public class PathValidator { public class PathValidator {
private static final String standardSuffix = "($|/|\\?)"; private static final String standardSuffix = "($|/|\\?)";
private static final String[] standardSuffixIdentifier = new String[]{"$", "/", "\\?"}; private static final String[] standardSuffixIdentifier = new String[]{"$", "/"};
public LocationEntry checkOverlapRestriction(Long vsId, LocationEntry addingEntry, List<LocationEntry> retainedEntries) throws ValidationException { public LocationEntry checkOverlapRestriction(Long vsId, LocationEntry addingEntry, List<LocationEntry> retainedEntries) throws ValidationException {
if (addingEntry == null) { if (addingEntry == null) {

View file

@ -6,7 +6,6 @@ import com.ctrip.zeus.dal.core.RelGroupVsDo;
import com.ctrip.zeus.exceptions.ValidationException; import com.ctrip.zeus.exceptions.ValidationException;
import com.ctrip.zeus.model.entity.*; import com.ctrip.zeus.model.entity.*;
import com.ctrip.zeus.service.model.handler.GroupValidator; import com.ctrip.zeus.service.model.handler.GroupValidator;
import com.ctrip.zeus.service.model.handler.impl.DefaultGroupValidator;
import com.ctrip.zeus.util.PathUtils; import com.ctrip.zeus.util.PathUtils;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.junit.Assert; import org.junit.Assert;
@ -110,26 +109,23 @@ public class PathValidationTest extends AbstractServerTest {
String s3 = "(restapi|html5|market|webapp)($|/|\\?)"; String s3 = "(restapi|html5|market|webapp)($|/|\\?)";
String s4 = "members($|/|\\?)|membersite($|/|\\?)"; String s4 = "members($|/|\\?)|membersite($|/|\\?)";
DefaultGroupValidator tmp = (DefaultGroupValidator) groupModelValidator; Pattern p = Pattern.compile("^((\\w|-)+/?)(\\$)?");
Pattern p = Pattern.compile("^((\\w|-)+/?)(\\$|\\\\\\?)?");
List<String> r; List<String> r;
try { try {
r = pathValidator.splitParallelPaths(s1, 1); r = pathValidator.splitParallelPaths(s1, 1);
Assert.assertEquals(3, r.size()); Assert.assertEquals(2, r.size());
Assert.assertEquals("Thingstodo-Order-OrderService$", r.get(0)); Assert.assertEquals("Thingstodo-Order-OrderService$", r.get(0));
Assert.assertEquals("Thingstodo-Order-OrderService/", r.get(1)); Assert.assertEquals("Thingstodo-Order-OrderService/", r.get(1));
Assert.assertEquals("Thingstodo-Order-OrderService\\?", r.get(2));
Assert.assertTrue(p.matcher(r.get(0)).matches()); Assert.assertTrue(p.matcher(r.get(0)).matches());
Assert.assertTrue(p.matcher(r.get(1)).matches()); Assert.assertTrue(p.matcher(r.get(1)).matches());
Assert.assertTrue(p.matcher(r.get(2)).matches());
} catch (ValidationException e) { } catch (ValidationException e) {
Assert.assertTrue(false); Assert.assertTrue(false);
} }
try { try {
r = pathValidator.splitParallelPaths(s2, 1); r = pathValidator.splitParallelPaths(s2, 1);
Assert.assertEquals(6, r.size()); Assert.assertEquals(4, r.size());
Assert.assertTrue(p.matcher(r.get(0)).matches()); Assert.assertTrue(p.matcher(r.get(0)).matches());
Assert.assertFalse(p.matcher(r.get(1)).matches()); Assert.assertFalse(p.matcher(r.get(1)).matches());
} catch (ValidationException e) { } catch (ValidationException e) {
@ -138,26 +134,22 @@ public class PathValidationTest extends AbstractServerTest {
try { try {
r = pathValidator.splitParallelPaths(s3, 1); r = pathValidator.splitParallelPaths(s3, 1);
Assert.assertEquals(12, r.size()); Assert.assertEquals(8, r.size());
Assert.assertEquals("restapi$", r.get(0)); Assert.assertEquals("restapi$", r.get(0));
Assert.assertEquals("restapi/", r.get(1)); Assert.assertEquals("restapi/", r.get(1));
Assert.assertEquals("restapi\\?", r.get(2)); Assert.assertEquals("html5$", r.get(2));
Assert.assertEquals("html5$", r.get(3)); Assert.assertEquals("html5/", r.get(3));
Assert.assertEquals("html5/", r.get(4));
Assert.assertEquals("html5\\?", r.get(5));
} catch (ValidationException e) { } catch (ValidationException e) {
Assert.assertTrue(false); Assert.assertTrue(false);
} }
try { try {
r = pathValidator.splitParallelPaths(s4, 1); r = pathValidator.splitParallelPaths(s4, 1);
Assert.assertEquals(6, r.size()); Assert.assertEquals(4, r.size());
Assert.assertEquals("members$", r.get(0)); Assert.assertEquals("members$", r.get(0));
Assert.assertEquals("members/", r.get(1)); Assert.assertEquals("members/", r.get(1));
Assert.assertEquals("members\\?", r.get(2)); Assert.assertEquals("membersite$", r.get(2));
Assert.assertEquals("membersite$", r.get(3)); Assert.assertEquals("membersite/", r.get(3));
Assert.assertEquals("membersite/", r.get(4));
Assert.assertEquals("membersite\\?", r.get(5));
} catch (ValidationException e) { } catch (ValidationException e) {
Assert.assertTrue(false); Assert.assertTrue(false);
} }