diff --git a/org.springframework.web/src/main/java/org/springframework/web/util/UriComponents.java b/org.springframework.web/src/main/java/org/springframework/web/util/UriComponents.java index 114ef85bd1..a5b4ec74b9 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/util/UriComponents.java +++ b/org.springframework.web/src/main/java/org/springframework/web/util/UriComponents.java @@ -37,12 +37,8 @@ import org.springframework.util.StringUtils; /** * Represents an immutable collection of URI components, mapping component type to string values. Contains convenience - * getters for all components, as well as the regular {@link Map} implementation. Effectively similar to {@link URI}, - * but with more powerful encoding options. - *
- * Note that this {@code Map} does not contain entries for {@link Type#PATH_SEGMENT} - * nor {@link Type#QUERY_PARAM}, since those components can occur multiple - * times in the URI. Instead, one can use {@link #getPathSegments()} or {@link #getQueryParams()} respectively. + * getters for all components. Effectively similar to {@link URI}, but with more powerful encoding options and support + * for URI template variables. * * @author Arjen Poutsma * @since 3.1 @@ -73,28 +69,44 @@ public final class UriComponents { private final boolean encoded; + /** + * Package-friendly constructor that creates a new {@code UriComponents} instance from the given parameters. All + * parameters are optional, and can be {@code null}. + * + * @param scheme the scheme + * @param userInfo the user info + * @param host the host + * @param port the port + * @param path the path component + * @param queryParams the query parameters + * @param fragment the fragment + * @param encoded whether the components are encoded + * @param verify whether the components need to be verified to determine whether they contain illegal characters + */ UriComponents(String scheme, - String userInfo, - String host, - int port, - PathComponent path, - MultiValueMapContains methods to indicate whether a given character is valid in a specific URI component.
+ * Contains methods to indicate whether a given character is valid in a specific URI component.
*
* @author Arjen Poutsma
* @see RFC 3986
@@ -681,6 +750,8 @@ public final class UriComponents {
PathComponent encode(String encoding) throws UnsupportedEncodingException;
+ void verify();
+
PathComponent expand(UriTemplateVariables uriVariables);
}
@@ -711,6 +782,10 @@ public final class UriComponents {
return new FullPathComponent(encodedPath);
}
+ public void verify() {
+ verifyUriComponent(path, Type.PATH);
+ }
+
public PathComponent expand(UriTemplateVariables uriVariables) {
String expandedPath = expandUriComponent(getPath(), uriVariables);
return new FullPathComponent(expandedPath);
@@ -771,6 +846,12 @@ public final class UriComponents {
return new PathSegmentComponent(encodedPathSegments);
}
+ public void verify() {
+ for (String pathSegment : getPathSegments()) {
+ verifyUriComponent(pathSegment, Type.PATH_SEGMENT);
+ }
+ }
+
public PathComponent expand(UriTemplateVariables uriVariables) {
List