Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 53e3af6

Browse files
committed
Merge pull request #172 from sfuhrm/link-fixes-quotes
JERSEY-2880: Link HTTP Header: Headers may contain double-quote-less parameters.
2 parents c1ae216 + 26f211c commit 53e3af6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core-common/src/main/java/org/glassfish/jersey/message/internal/LinkProvider.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ static JerseyLink.Builder initBuilder(JerseyLink.Builder lb, String value) {
106106
checkToken(st, ";");
107107
String n = st.nextToken().trim();
108108
checkToken(st, "=");
109-
checkToken(st, "\"");
110-
String v = st.nextToken();
111-
checkToken(st, "\"");
109+
110+
String v = nextNonEmptyToken(st);
111+
if (v.equals("\"")) {
112+
v = st.nextToken();
113+
checkToken(st, "\"");
114+
}
115+
112116
lb.param(n, v);
113117
}
114118
}
@@ -124,6 +128,17 @@ static JerseyLink.Builder initBuilder(JerseyLink.Builder lb, String value) {
124128
return lb;
125129
}
126130

131+
private static String nextNonEmptyToken(StringTokenizer st) throws IllegalArgumentException {
132+
String token = null;
133+
do {
134+
token = st.nextToken().trim();
135+
} while (token.length() == 0);
136+
if (token == null) {
137+
throw new IllegalArgumentException("Non-Empty token not found");
138+
}
139+
return token;
140+
}
141+
127142
private static void checkToken(StringTokenizer st, String expected) throws IllegalArgumentException {
128143
String token;
129144
do {

core-common/src/test/java/org/glassfish/jersey/message/internal/LinkProviderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,12 @@ public void testRoundTrip() {
118118
Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=\"bar1\"; foo2 = \"bar2\"");
119119
assertEquals(l1, l2);
120120
}
121+
122+
@Test
123+
public void testWithoutDoubleQuotes() {
124+
Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
125+
assertEquals(l1, Link.valueOf(l1.toString()));
126+
Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=bar1; foo2 = bar2");
127+
assertEquals(l1, l2);
128+
}
121129
}

0 commit comments

Comments
 (0)