#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.
This commit is contained in:
committed by
Greg Turnquist
parent
13db7c7fb2
commit
21719bb041
@@ -4,8 +4,6 @@ jdk:
|
||||
env:
|
||||
matrix:
|
||||
- PROFILE=non-existant
|
||||
- PROFILE=spring43-next
|
||||
- PROFILE=spring5
|
||||
- PROFILE=spring5-next
|
||||
addons:
|
||||
apt:
|
||||
|
||||
1
pom.xml
1
pom.xml
@@ -88,6 +88,7 @@
|
||||
<id>spring5-next</id>
|
||||
<properties>
|
||||
<spring.version>5.0.2.BUILD-SNAPSHOT</spring.version>
|
||||
<jackson.version>2.9.2</jackson.version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class Links implements Iterable<Link> {
|
||||
|
||||
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\w+=\"[^\"]*\")+)");
|
||||
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\s*\\w+=\"[^\"]*\")+)");
|
||||
|
||||
static final Links NO_LINKS = new Links(Collections.emptyList());
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class LinksUnitTest {
|
||||
static final String FIRST = "</something>;rel=\"foo\"";
|
||||
static final String SECOND = "</somethingElse>;rel=\"bar\"";
|
||||
static final String WITH_COMMA = "<http://localhost:8080/test?page=0&filter=foo,bar>;rel=\"foo\"";
|
||||
static final String WITH_WHITESPACE = "</something>; rel=\"foo\"," + SECOND;
|
||||
|
||||
static final String LINKS = StringUtils.collectionToCommaDelimitedString(Arrays.asList(FIRST, SECOND));
|
||||
|
||||
@@ -93,4 +94,12 @@ public class LinksUnitTest {
|
||||
assertThat(twoWithCommaInFirst.getLink("foo")).hasValue(withComma);
|
||||
assertThat(twoWithCommaInFirst.getLink("bar")).hasValue(new Link("/somethingElse", "bar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5988#section-5.5
|
||||
*/
|
||||
@Test
|
||||
public void parsesLinksWithWhitespace() {
|
||||
assertThat(Links.valueOf(WITH_WHITESPACE)).isEqualTo(reference);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user