@@ -104,8 +104,8 @@ private Link(String href, @Nullable UriTemplate template, LinkRelation rel, List
104
104
}
105
105
106
106
Link (LinkRelation rel , String href , @ Nullable String hreflang , @ Nullable String media , @ Nullable String title ,
107
- @ Nullable String type , @ Nullable String deprecation , @ Nullable String profile , @ Nullable String name ,
108
- @ Nullable UriTemplate template , List <Affordance > affordances ) {
107
+ @ Nullable String type , @ Nullable String deprecation , @ Nullable String profile , @ Nullable String name ,
108
+ @ Nullable UriTemplate template , List <Affordance > affordances ) {
109
109
110
110
this .rel = rel ;
111
111
this .href = href ;
@@ -383,15 +383,13 @@ public URI toUri() {
383
383
* Factory method to easily create {@link Link} instances from RFC-8288 compatible {@link String} representations of a
384
384
* link.
385
385
*
386
- * @param element an RFC-8288 compatible representation of a link.
386
+ * @param source an RFC-8288 compatible representation of a link.
387
387
* @throws IllegalArgumentException if a {@link String} was given that does not adhere to RFC-8288.
388
388
* @throws IllegalArgumentException if no {@code rel} attribute could be found.
389
- * @return The parsed link
390
- * @deprecated Use {@link Links#parse(String)} instead. This method parses only the first link from a list of links.
389
+ * @return will never be {@literal null}.
391
390
*/
392
- @ Deprecated
393
- public static Link valueOf (String element ) {
394
- return LinkParser .parseLink (element , new int []{0 });
391
+ public static Link valueOf (String source ) {
392
+ return LinkParser .parseLink (source , new int [] { 0 });
395
393
}
396
394
397
395
/**
@@ -596,12 +594,15 @@ public int hashCode() {
596
594
*/
597
595
@ Override
598
596
public String toString () {
599
- StringBuilder result = new StringBuilder (64 );
597
+
598
+ var result = new StringBuilder (64 );
599
+
600
600
result .append ('<' )
601
601
// We only url-encode the `>`. We expect other special chars to already be escaped. `;` and `,` need not
602
602
// be escaped within the URL
603
603
.append (href .replace (">" , "%3e" ))
604
604
.append (">;rel=" );
605
+
605
606
quoteParamValue (rel .value (), result );
606
607
607
608
if (hreflang != null ) {
@@ -646,20 +647,26 @@ public String toString() {
646
647
* Quotes the given string `s` and appends the result to the `target`. This method appends the start quote, the
647
648
* escaped text, and the end quote.
648
649
*
649
- * @param s Text to quote
650
+ * @param s Text to quote
650
651
* @param target StringBuilder to append to
651
652
*/
652
- private void quoteParamValue (String s , StringBuilder target ) {
653
+ private static void quoteParamValue (String s , StringBuilder target ) {
654
+
653
655
// we reserve extra 4 chars: two for the start and end quote, another two are a reserve for potential escaped chars
654
656
target .ensureCapacity (target .length () + s .length () + 4 );
655
657
target .append ('"' );
658
+
656
659
for (int i = 0 , l = s .length (); i < l ; i ++) {
660
+
657
661
char ch = s .charAt (i );
662
+
658
663
if (ch == '"' || ch == '\\' ) {
659
664
target .append ('\\' );
660
665
}
666
+
661
667
target .append (ch );
662
668
}
669
+
663
670
target .append ('"' );
664
671
}
665
672
0 commit comments