Encapsulate full path initialization
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -107,10 +107,9 @@ public abstract class RequestPredicates {
|
||||
*/
|
||||
public static RequestPredicate path(String pattern) {
|
||||
Assert.notNull(pattern, "'pattern' must not be null");
|
||||
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
|
||||
pattern = "/" + pattern;
|
||||
}
|
||||
return pathPredicates(PathPatternParser.defaultInstance).apply(pattern);
|
||||
PathPatternParser parser = PathPatternParser.defaultInstance;
|
||||
pattern = parser.initFullPathPattern(pattern);
|
||||
return pathPredicates(parser).apply(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,14 +332,14 @@ public abstract class RequestPredicates {
|
||||
void method(Set<HttpMethod> methods);
|
||||
|
||||
/**
|
||||
* Receive notification of an path predicate.
|
||||
* Receive notification of a path predicate.
|
||||
* @param pattern the path pattern that makes up the predicate
|
||||
* @see RequestPredicates#path(String)
|
||||
*/
|
||||
void path(String pattern);
|
||||
|
||||
/**
|
||||
* Receive notification of an path extension predicate.
|
||||
* Receive notification of a path extension predicate.
|
||||
* @param extension the path extension that makes up the predicate
|
||||
* @see RequestPredicates#pathExtension(String)
|
||||
*/
|
||||
@@ -426,11 +425,11 @@ public abstract class RequestPredicates {
|
||||
void unknown(RequestPredicate predicate);
|
||||
}
|
||||
|
||||
|
||||
private static class HttpMethodPredicate implements RequestPredicate {
|
||||
|
||||
private final Set<HttpMethod> httpMethods;
|
||||
|
||||
|
||||
public HttpMethodPredicate(HttpMethod httpMethod) {
|
||||
Assert.notNull(httpMethod, "HttpMethod must not be null");
|
||||
this.httpMethods = EnumSet.of(httpMethod);
|
||||
@@ -641,12 +640,14 @@ public abstract class RequestPredicates {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class PathExtensionPredicate implements RequestPredicate {
|
||||
|
||||
private final Predicate<String> extensionPredicate;
|
||||
|
||||
@Nullable
|
||||
private final String extension;
|
||||
|
||||
public PathExtensionPredicate(Predicate<String> extensionPredicate) {
|
||||
Assert.notNull(extensionPredicate, "Predicate must not be null");
|
||||
this.extensionPredicate = extensionPredicate;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.PathMatcher;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
/**
|
||||
* A logical disjunction (' || ') request condition that matches a request
|
||||
@@ -142,9 +143,7 @@ public class PatternsRequestCondition extends AbstractRequestCondition<PatternsR
|
||||
}
|
||||
Set<String> result = new LinkedHashSet<>(patterns.length);
|
||||
for (String pattern : patterns) {
|
||||
if (StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
|
||||
pattern = "/" + pattern;
|
||||
}
|
||||
pattern = PathPatternParser.defaultInstance.initFullPathPattern(pattern);
|
||||
result.add(pattern);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -65,6 +65,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
/**
|
||||
* Creates instances of {@link org.springframework.web.util.UriComponentsBuilder}
|
||||
@@ -545,9 +546,7 @@ public class MvcUriComponentsBuilder {
|
||||
String typePath = getClassMapping(controllerType);
|
||||
String methodPath = getMethodMapping(method);
|
||||
String path = pathMatcher.combine(typePath, methodPath);
|
||||
if (StringUtils.hasLength(path) && !path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
path = PathPatternParser.defaultInstance.initFullPathPattern(path);
|
||||
builder.path(path);
|
||||
|
||||
return applyContributors(builder, method, args);
|
||||
|
||||
Reference in New Issue
Block a user