#1903 - Fix link header parsing for multiple links and unquoted attribute values.
Fixed the regular expression to parse link header values to properly consider the comma to end an unquoted attribute value, too. Couple of additional unit tests, too.
This commit is contained in:
@@ -45,7 +45,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
public class Links implements Iterable<Link> {
|
||||
|
||||
public static final Links NONE = new Links(Collections.emptyList());
|
||||
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\s*\\w+=\"?[^\"]*\"?)+)");
|
||||
private static final Pattern LINK_HEADER_PATTERN = Pattern.compile("(<[^>]*>(;\\s*\\w+=\"?[^\",]*\"?)+)");
|
||||
|
||||
private final List<Link> links;
|
||||
|
||||
@@ -91,8 +91,8 @@ public class Links implements Iterable<Link> {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
Matcher matcher = LINK_HEADER_PATTERN.matcher(source);
|
||||
List<Link> links = new ArrayList<>();
|
||||
Matcher matcher = LINK_HEADER_PATTERN.matcher(source);
|
||||
|
||||
while (matcher.find()) {
|
||||
|
||||
|
||||
@@ -55,10 +55,13 @@ class LinksUnitTest {
|
||||
Link.of("/somethingElse", "bar").withHreflang("de"));
|
||||
|
||||
// #1899
|
||||
static final String FIVE = "</somethingElse>;rel=boo";
|
||||
static final String FIVE = "</somethingElse?foo=one,two>;rel=boo";
|
||||
static final String SIX = "</somethingElse>; rel=bee";
|
||||
static final String LINKS3 = StringUtils.collectionToCommaDelimitedString(Arrays.asList(FIVE, SIX));
|
||||
static final Links reference3 = Links.of(Link.of("/somethingElse", "boo"), Link.of("/somethingElse", "bee"));
|
||||
static final String SEVEN = "</somethingElse>;rel=beeboo;title=sometitle";
|
||||
static final String LINKS3 = StringUtils.collectionToCommaDelimitedString(Arrays.asList(FIVE, SIX, SEVEN));
|
||||
static final Links reference3 = Links.of(Link.of("/somethingElse?foo=one,two", "boo"), //
|
||||
Link.of("/somethingElse", "bee"),
|
||||
Link.of("/somethingElse", "beeboo").withTitle("sometitle"));
|
||||
|
||||
@Test
|
||||
void parsesLinkHeaderLinks() {
|
||||
|
||||
Reference in New Issue
Block a user