PathPatternRouteMatcher should use custom separator

Prior to this commit, the `PathPatternRouteMatcher` would always use the
default path pattern separator when parsing incoming route strings to
`RouteMatcher.Route` instances.
When the `PathPatternRouteMatcher` is configured with a
`PathPatternParser` that has a custom separator (e.g., `.`), then the
matching algorithm can't match routes against parsed patterns.

This commit ensures that the route matcher uses the configured separator
at all times.

Fixes gh-23167
This commit is contained in:
Brian Clozel
2019-06-20 20:23:04 +02:00
parent f56c54dfc8
commit 5787fc16fb
2 changed files with 53 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* 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
*
* https://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 org.springframework.web.util.pattern;
import org.junit.Test;
import org.springframework.util.RouteMatcher;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for the {@link PathPatternRouteMatcher}
* @author Brian Clozel
*/
public class PathPatternRouteMatcherTest {
PathPatternRouteMatcher routeMatcher = new PathPatternRouteMatcher(new PathPatternParser());
@Test
public void matchRoute() {
RouteMatcher.Route route = routeMatcher.parseRoute("/projects/spring-framework");
assertThat(routeMatcher.match("/projects/{name}", route)).isTrue();
}
@Test
public void matchRouteCustomSeparator() {
PathPatternParser pathPatternParser = new PathPatternParser();
pathPatternParser.setSeparator('.');
PathPatternRouteMatcher routeMatcher = new PathPatternRouteMatcher(pathPatternParser);
RouteMatcher.Route route = routeMatcher.parseRoute("projects.spring-framework");
assertThat(routeMatcher.match("projects.{name}", route)).isTrue();
}
}