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:
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user