Skip to content

Commit 21719bb

Browse files
Christian Bühlergregturn
Christian Bühler
authored andcommitted
#686 - Support whitespace in Links header (RFC 5988).
RFC 5988 (https://tools.ietf.org/html/rfc5988#section-5.5) has clear examples of whitespace in link headers. This commit introduces support (and tests) to support these spec cases.
1 parent 13db7c7 commit 21719bb

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ jdk:
44
env:
55
matrix:
66
- PROFILE=non-existant
7-
- PROFILE=spring43-next
8-
- PROFILE=spring5
97
- PROFILE=spring5-next
108
addons:
119
apt:

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<id>spring5-next</id>
8989
<properties>
9090
<spring.version>5.0.2.BUILD-SNAPSHOT</spring.version>
91+
<jackson.version>2.9.2</jackson.version>
9192
</properties>
9293
<repositories>
9394
<repository>

src/main/java/org/springframework/hateoas/Links.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class Links implements Iterable<Link> {
3737

38-
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\w+=\"[^\"]*\")+)");
38+
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\s*\\w+=\"[^\"]*\")+)");
3939

4040
static final Links NO_LINKS = new Links(Collections.emptyList());
4141

src/test/java/org/springframework/hateoas/LinksUnitTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class LinksUnitTest {
3434
static final String FIRST = "</something>;rel=\"foo\"";
3535
static final String SECOND = "</somethingElse>;rel=\"bar\"";
3636
static final String WITH_COMMA = "<http://localhost:8080/test?page=0&filter=foo,bar>;rel=\"foo\"";
37+
static final String WITH_WHITESPACE = "</something>; rel=\"foo\"," + SECOND;
3738

3839
static final String LINKS = StringUtils.collectionToCommaDelimitedString(Arrays.asList(FIRST, SECOND));
3940

@@ -93,4 +94,12 @@ public void parsesLinkWithComma() {
9394
assertThat(twoWithCommaInFirst.getLink("foo")).hasValue(withComma);
9495
assertThat(twoWithCommaInFirst.getLink("bar")).hasValue(new Link("/somethingElse", "bar"));
9596
}
97+
98+
/**
99+
* @see https://tools.ietf.org/html/rfc5988#section-5.5
100+
*/
101+
@Test
102+
public void parsesLinksWithWhitespace() {
103+
assertThat(Links.valueOf(WITH_WHITESPACE)).isEqualTo(reference);
104+
}
96105
}

0 commit comments

Comments
 (0)