Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/main/java/com/emarsys/escher/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ public String canonicalize(EscherRequest request, List<String> signedHeaders) th
}


private String canonicalizePath(EscherRequest request) throws EscherException {
try {
String path = request.getURI().toURL().getPath();
return path.equals("") ? "/" : path;
} catch (MalformedURLException e) {
throw new EscherException(e);
}
private String canonicalizePath(EscherRequest request) {
String path = request.getURI().getRawPath();
return path.isEmpty() ? "/" : path;
}


Expand All @@ -72,7 +68,7 @@ private String queryParameterToString(NameValuePair entry) {


public static String encodeURIComponent(String s) throws UnsupportedEncodingException {
// We need this to be uri encoded (' ' => '%20') not x-www-form-urlencoded (' ' => '+') with
// We need this to be uri encoded (' ' => '%20') not x-www-form-urlencoded (' ' => '+') with
// some of the RFC3986 reserved characters kept as they were (-._~) which is used by URLEncoder.
// This will result an encoding method similar to other escher libs.
return URLEncoder.encode(s, "UTF-8")
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/emarsys/escher/HelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ public void testCanonicalizeWithUrlParamsContainingSpecialCharacters() throws Ex
assertThat(canonicalized, containsString("specialchars=-_.~"));
}

@Test
public void testCanonicalizeWithRelativeUri() throws Exception {
TestParam param = parseTestData("get-vanilla");
TestParam.Request paramRequest = param.getRequest();
paramRequest.setUrl(paramRequest.getUrl() + "?name=John%2BWick");

URI relativeUri = new URI(paramRequest.getUrl());

EscherRequestImpl request = new EscherRequestImpl(paramRequest.getMethod(), relativeUri, new ArrayList<>(), paramRequest.getBody());

Helper helper = new Helper(createConfig(param));

String canonicalized = helper.canonicalize(request, param.getHeadersToSign());

assertThat(canonicalized, containsString("name=John%2BWick"));
}


@Test
@UseDataProvider("getAddMandatoryHeadersCases")
Expand Down
Loading