From 2504ae3fac8aadae80eff0e205cbf718b43fc93b Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 24 Jul 2020 08:46:28 +0200 Subject: [PATCH] #1314 - HalLinkRelations now properly parses link relations with more than one colon. Previously the parsing of link relations had assumed that a curie relation only consists of a single colon, thus, that a split by colon would always end up in two elements and only re-assembled these two elements. In case a URI that contains multiple colons handed into the parsing method, further segments had been dropped. We now remain everything following the first colon as local part of the URI. Also, we now detect IANA registered URI schemes [0] and consider source relations starting with those as uncuried ones. [0] https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml --- .../hateoas/IanaUriSchemes.java | 370 ++++++++++++++++++ .../mediatype/hal/HalLinkRelation.java | 10 +- .../hal/HalLinkRelationUnitTest.java | 20 + 3 files changed, 396 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/springframework/hateoas/IanaUriSchemes.java diff --git a/src/main/java/org/springframework/hateoas/IanaUriSchemes.java b/src/main/java/org/springframework/hateoas/IanaUriSchemes.java new file mode 100644 index 00000000..a0ec203b --- /dev/null +++ b/src/main/java/org/springframework/hateoas/IanaUriSchemes.java @@ -0,0 +1,370 @@ +/* + * Copyright 2020 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.hateoas; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; + +/** + * A list of well-defined URI schemes governed by IANA. + * + * @author Oliver Drotbohm + * @see supportsMultipleColons() { + + return DynamicTest.stream(Arrays.asList("urn:ietf:rfc", "http://example.com/?test=foo:bar").iterator(), // + it -> it + " should be returned as link relation as is.", // + it -> { + + HalLinkRelation relation = HalLinkRelation.of(LinkRelation.of(it)); + + assertThat(relation.value()).isEqualTo(it); + assertThat(relation.getLocalPart()).isEqualTo(it); + assertThat(relation.isCuried()).isFalse(); + }); + } }