Vinz2168 commented on PR #11791:
URL: https://github.com/apache/nifi/pull/11791#issuecomment-6108227415

   Regarding the `&` / `+` limitation in branch and bucket names: it comes from 
`StandardHttpUriBuilder.build()` using the multi-argument `URI` constructor, 
which only quotes characters that are illegal in a query, so `&`, `+` and `=` 
pass through unencoded. Pre-encoding with `URLEncoder` before 
`addQueryParameter()` doesn't help either, because the `%` would be 
double-encoded.
   
   One option within this PR is to build the path with `HttpUriBuilder` and 
append the query encoded with `URLEncoder`:
   
   ```java
   private static URI withQuery(final URI uri, final Map<String, String> 
parameters) {
       final String query = parameters.entrySet().stream()
               .map(entry -> URLEncoder.encode(entry.getKey(), 
StandardCharsets.UTF_8) + "="
                       + URLEncoder.encode(entry.getValue(), 
StandardCharsets.UTF_8))
               .collect(Collectors.joining("&"));
       return URI.create(uri.toASCIIString() + "?" + query);
   }
   ```
   
   Gitea and Forgejo parse the query with Go's `net/url`, which decodes `+` as 
a space, so the `URLEncoder` form encoding round-trips correctly.
   
   That said, fixing it in `StandardHttpUriBuilder` (encoding query names and 
values with `URLEncoder` and building the URI from the encoded string) would 
also remove the same limitation from the Bitbucket and Azure DevOps clients, so 
it may be better handled in a separate Jira issue.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to