Skip to content

Commit a74e45a

Browse files
committed
http Issue 189: Update UriTemplate to RFC 6570
https://codereview.appspot.com/7521043/
1 parent 3d45f2c commit a74e45a

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

google-http-client/src/main/java/com/google/api/client/http/UriTemplate.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Expands URI Templates.
3030
*
3131
* This Class supports Level 1 templates and all Level 4 composite templates as described in:
32-
* <a href="http://tools.ietf.org/html/draft-gregorio-uritemplate-07">URI Template</a>.
32+
* <a href="http://tools.ietf.org/html/rfc6570">RFC 6570</a>.
3333
*
3434
* Specifically, for the variables:
3535
* var := "value"
@@ -40,36 +40,36 @@
4040
* {var} -> value
4141
* {list} -> red,green,blue
4242
* {list*} -> red,green,blue
43-
* {key} -> semi,%3B,dot,.,comma,%2C
44-
* {key*} -> semi=%3B,dot=.,comma=%2C
43+
* {keys} -> semi,%3B,dot,.,comma,%2C
44+
* {keys*} -> semi=%3B,dot=.,comma=%2C
4545
* {+list} -> red,green,blue
4646
* {+list*} -> red,green,blue
47-
* {+key} -> semi,;,dot,.,comma,,
48-
* {+key*} -> semi=;,dot=.,comma=,
47+
* {+keys} -> semi,;,dot,.,comma,,
48+
* {+keys*} -> semi=;,dot=.,comma=,
4949
* {#list} -> #red,green,blue
5050
* {#list*} -> #red,green,blue
51-
* {#key} -> #semi,;,dot,.,comma,,
52-
* {#key*} -> #semi=;,dot=.,comma=,
51+
* {#keys} -> #semi,;,dot,.,comma,,
52+
* {#keys*} -> #semi=;,dot=.,comma=,
5353
* X{.list} -> X.red,green,blue
5454
* X{.list*} -> X.red.green.blue
55-
* X{.key} - > X.semi,%3B,dot,.,comma,%2C
56-
* X{.key*} -> X.semi=%3B.dot=..comma=%2C
55+
* X{.keys} -> X.semi,%3B,dot,.,comma,%2C
56+
* X{.keys*} -> X.semi=%3B.dot=..comma=%2C
5757
* {/list} -> /red,green,blue
5858
* {/list*} -> /red/green/blue
59-
* {/key} -> /semi,%3B,dot,.,comma,%2C
60-
* {/key*} -> /semi=%3B/dot=./comma=%2C
59+
* {/keys} -> /semi,%3B,dot,.,comma,%2C
60+
* {/keys*} -> /semi=%3B/dot=./comma=%2C
6161
* {;list} -> ;list=red,green,blue
62-
* {;list*} -> ;red;green;blue
63-
* {;key} -> ;keys=semi,%3B,dot,.,comma,%2C
64-
* {;key*} -> ;semi=%3B;dot=.;comma=%2C
62+
* {;list*} -> ;list=red;list=green;list=blue
63+
* {;keys} -> ;keys=semi,%3B,dot,.,comma,%2C
64+
* {;keys*} -> ;semi=%3B;dot=.;comma=%2C
6565
* {?list} -> ?list=red,green,blue
66-
* {?list*} -> ?red&green&blue
67-
* {?key} -> ?keys=semi,%3B,dot,.,comma,%2C
68-
* {?key*} -> ?semi=%3B&dot=.&comma=%2C
66+
* {?list*} -> ?list=red&list=green&list=blue
67+
* {?keys} -> ?keys=semi,%3B,dot,.,comma,%2C
68+
* {?keys*} -> ?semi=%3B&dot=.&comma=%2C
6969
* {&list} -> &list=red,green,blue
70-
* {&list*} -> &red&green&blue
71-
* {&key} -> &keys=semi,%3B,dot,.,comma,%2C
72-
* {&key*} -> &semi=%3B&dot=.&comma=%2C
70+
* {&list*} -> &list=red&list=green&list=blue
71+
* {&keys} -> &keys=semi,%3B,dot,.,comma,%2C
72+
* {&keys*} -> &semi=%3B&dot=.&comma=%2C
7373
*
7474
* @since 1.6
7575
* @author Ravi Mistry
@@ -226,7 +226,7 @@ private static Map<String, Object> getMap(Object obj) {
226226
*
227227
* <p>
228228
* Supports Level 1 templates and all Level 4 composite templates as described in:
229-
* <a href="http://tools.ietf.org/html/draft-gregorio-uritemplate-07">URI Template</a>.
229+
* <a href="http://tools.ietf.org/html/rfc6570">RFC 6570</a>.
230230
* </p>
231231
*
232232
* @param baseUrl The base URL which the URI component is relative to.
@@ -260,7 +260,7 @@ public static String expand(String baseUrl, String uriTemplate, Object parameter
260260
*
261261
* <p>
262262
* Supports Level 1 templates and all Level 4 composite templates as described in:
263-
* <a href="http://tools.ietf.org/html/draft-gregorio-uritemplate-07">URI Template</a>.
263+
* <a href="http://tools.ietf.org/html/rfc6570">RFC 6570</a>.
264264
* </p>
265265
*
266266
* @param pathUri URI component. It may contain one or more sequences of the form "{name}", where
@@ -371,6 +371,10 @@ private static String getListPropertyValue(String varName, Iterator<?> iterator,
371371
}
372372
}
373373
while (iterator.hasNext()) {
374+
if (containsExplodeModifier && compositeOutput.requiresVarAssignment()) {
375+
retBuf.append(CharEscapers.escapeUriPath(varName));
376+
retBuf.append("=");
377+
}
374378
retBuf.append(compositeOutput.getEncodedValue(iterator.next().toString()));
375379
if (iterator.hasNext()) {
376380
retBuf.append(joiner);

google-http-client/src/test/java/com/google/api/client/http/UriTemplateTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ private Iterable<String> getListIterable() {
110110
{"{/d}", "/red,green,blue"},
111111
{"{/d*}", "/red/green/blue"},
112112
{"{;d}", ";d=red,green,blue"},
113-
{"{;d*}", ";red;green;blue"},
113+
{"{;d*}", ";d=red;d=green;d=blue"},
114114
{"{?d}", "?d=red,green,blue"},
115-
{"{?d*}", "?red&green&blue"},
115+
{"{?d*}", "?d=red&d=green&d=blue"},
116116
{"{&d}", "&d=red,green,blue"},
117-
{"{&d*}", "&red&green&blue"},
117+
{"{&d*}", "&d=red&d=green&d=blue"},
118118
};
119119

120120
public void testExpandTemplates_explodeIterator() {
@@ -237,8 +237,8 @@ public void testExpandTemplates_mixedBagParameters() {
237237
requestMap.put("unused1", "unused param");
238238
requestMap.put("unused2", "unused=param");
239239
assertEquals(
240-
"foo/xyz/red/green/blue&red&green&blue&map=semi,%3B,dot,.,comma,%2CONE?unused1=unused%20"
241-
+ "param&unused2=unused%3Dparam",
240+
"foo/xyz/red/green/blue&iterable=red&iterable=green&iterable=blue&map=semi,%3B,dot,.,comma"
241+
+ ",%2CONE?unused1=unused%20param&unused2=unused%3Dparam",
242242
UriTemplate.expand("foo/{abc}{/iterator*}{&iterable*}{&map}{&enum}", requestMap, true));
243243
// Assert the map has not changed.
244244
assertEquals(7, requestMap.size());

0 commit comments

Comments
 (0)