Escape & characaters in curl request URLs

Without escaping, the & will cause bash to truncate the URL and
background the curl process.

Closes gh-35
This commit is contained in:
Andy Wilkinson
2015-03-16 14:45:54 +00:00
parent c3efc4128f
commit 23a6388177
2 changed files with 3 additions and 3 deletions

View File

@@ -186,7 +186,7 @@ public abstract class CurlDocumentation {
private String getQueryString(HttpServletRequest request) {
if (request.getQueryString() != null) {
return request.getQueryString();
return request.getQueryString().replace("&", "\\&");
}
if (isGetRequest(request)) {
return toQueryString(request.getParameterMap());
@@ -199,7 +199,7 @@ public abstract class CurlDocumentation {
for (Map.Entry<String, String[]> entry : map.entrySet()) {
for (String value : entry.getValue()) {
if (sb.length() > 0) {
sb.append("&");
sb.append("\\&");
}
sb.append(urlEncodeUTF8(entry.getKey())).append('=')
.append(urlEncodeUTF8(value));

View File

@@ -134,7 +134,7 @@ public class CurlDocumentationTests {
documentCurlRequest("request-with-multiple-parameters").handle(
new StubMvcResult(request, null));
assertThat(requestSnippetLines("request-with-multiple-parameters"),
hasItem("$ curl http://localhost/foo?k1=v1&k1=v1-bis&k2=v2 -i"));
hasItem("$ curl http://localhost/foo?k1=v1\\&k1=v1-bis\\&k2=v2 -i"));
}
@Test