diff --git a/src/main/java/org/springframework/hateoas/Link.java b/src/main/java/org/springframework/hateoas/Link.java index 95457ae1..11ac811d 100755 --- a/src/main/java/org/springframework/hateoas/Link.java +++ b/src/main/java/org/springframework/hateoas/Link.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -43,6 +43,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; public class Link implements Serializable { private static final long serialVersionUID = -9037755944661782121L; + private static final String URI_PATTERN = "(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; public static final String ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"; @@ -282,7 +283,7 @@ public class Link implements Serializable { } Map attributes = new HashMap(); - Pattern keyAndValue = Pattern.compile("(\\w+)=\\\"(\\p{Alnum}*)\""); + Pattern keyAndValue = Pattern.compile("(\\w+)=\"(\\p{Lower}[\\p{Lower}\\p{Digit}\\.\\-]*|" + URI_PATTERN + ")\""); Matcher matcher = keyAndValue.matcher(source); while (matcher.find()) { diff --git a/src/test/java/org/springframework/hateoas/LinkUnitTest.java b/src/test/java/org/springframework/hateoas/LinkUnitTest.java index 4d336391..727822f2 100644 --- a/src/test/java/org/springframework/hateoas/LinkUnitTest.java +++ b/src/test/java/org/springframework/hateoas/LinkUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -173,4 +173,22 @@ public class LinkUnitTest { Link link = new Link("/customer/{customerId}/programs", "programs"); assertThat(link.getHref(), is("/customer/{customerId}/programs")); } + + /** + * @see #504 + */ + @Test + public void parsesLinkRelationWithDotAndMinus() { + assertThat(Link.valueOf("; rel=\"rel-with-minus-and-.\"").getRel(), is("rel-with-minus-and-.")); + } + + /** + * @see #504 + */ + @Test + public void parsesUriLinkRelations() { + + assertThat(Link.valueOf("; rel=\"http://acme.com/rels/foo-bar\"").getRel(), + is("http://acme.com/rels/foo-bar")); + } }