diff --git a/spring-restdocs/src/main/java/org/springframework/restdocs/curl/CurlDocumentation.java b/spring-restdocs/src/main/java/org/springframework/restdocs/curl/CurlDocumentation.java index cd738df7..882806a6 100644 --- a/spring-restdocs/src/main/java/org/springframework/restdocs/curl/CurlDocumentation.java +++ b/spring-restdocs/src/main/java/org/springframework/restdocs/curl/CurlDocumentation.java @@ -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 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)); diff --git a/spring-restdocs/src/test/java/org/springframework/restdocs/curl/CurlDocumentationTests.java b/spring-restdocs/src/test/java/org/springframework/restdocs/curl/CurlDocumentationTests.java index caaa90e6..36735028 100644 --- a/spring-restdocs/src/test/java/org/springframework/restdocs/curl/CurlDocumentationTests.java +++ b/spring-restdocs/src/test/java/org/springframework/restdocs/curl/CurlDocumentationTests.java @@ -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