Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/715#discussion_r120018466
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
 ---
    @@ -181,7 +204,19 @@ private HttpRequest buildHttpRequest(String httpVerb, 
URI uri, Map<String, Strin
                     if (contentType == null || 
contentType.equalsIgnoreCase(APPLICATION_JSON)) {
                         LOG.warn("Content-Type not specified. Using {}, as 
default (continuing)", APPLICATION_JSON);
                         body = toJsonString(payload);
    -                } else if 
(!contentType.equalsIgnoreCase(APPLICATION_JSON)) {
    +                } else if 
(contentType.equalsIgnoreCase(APPLICATION_X_WWW_FORM_URLENCODE)) {
    +                    if (payload instanceof Map) {
    +                        for (Map.Entry<String, String> entry : 
((Map<String, String>) payload).entrySet()) {
    +                            try {
    +                                if (!body.equals("")) body += "&";
    +                                body += URLEncoder.encode(entry.getKey(), 
StandardCharsets.UTF_8.toString()) + "=" + URLEncoder.encode(entry.getValue(), 
StandardCharsets.UTF_8.toString());
    --- End diff --
    
    Yes, but 
    ```java
        public static final Logger LOG = 
LoggerFactory.getLogger(TempDeleteMe.class);
        @Test
        public void testit() throws Exception {
            String uri = new URI(null,  "<b>hello world</b> ",  
null).toASCIIString();
            String urlEncoder = URLEncoder.encode("<b>hello world</b> ", 
"UTF-8");
            System.out.println(uri);
            System.out.println(urlEncoder);
            Assert.assertEquals(uri, urlEncoder);
        }
    ```
    fails and prints
    ```
    %3Cb%3Ehello%20world%3C/b%3E%20
    %3Cb%3Ehello+world%3C%2Fb%3E+
    ```
    You probably just want your values to be escaped according to RFC 2396, 
which is what URI does (almost).  URLEncoder turns your value into 
`application/x-www-form-urlencoded`, which is not the same, and is especially 
unhelpful in how it treats space characters (`+`), which you probably want as 
`%20`, right?
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to