Skip to content

Commit

Permalink
Correctly encode path segments with Spring's UriUtils
Browse files Browse the repository at this point in the history
URLEncoder.encode is suitable for encoding query parameters
but not other URL/URI components (it encodes spaces as `+`s
instead of %-encoded values).

Fixes #97.
  • Loading branch information
michaelklishin committed Feb 2, 2017
1 parent 97450d2 commit 708ae77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/rabbitmq/http/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.rabbitmq.http.client;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -55,6 +55,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.util.UriUtils;

import javax.net.ssl.SSLContext;

Expand Down Expand Up @@ -578,7 +579,12 @@ private URI uriWithPath(final String path) {

@SuppressWarnings("deprecation")
private String encodePathSegment(final String pathSegment) {
return URLEncoder.encode(pathSegment);
try {
return UriUtils.encodePathSegment(pathSegment, "UTF-8");
} catch (UnsupportedEncodingException e) {
// the best we can do without messing up all caller signatures :/ MK.
return pathSegment;
}
}

private List<HttpMessageConverter<?>> getMessageConverters() {
Expand Down

0 comments on commit 708ae77

Please sign in to comment.