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
5 changes: 5 additions & 0 deletions src/main/java/com/crowdin/client/core/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.http.impl.http.ApacheHttpClient;
import com.crowdin.client.core.http.impl.util.RequestEncoder;
import com.crowdin.client.core.model.ClientConfig;
import com.crowdin.client.core.model.EnumConverter;
import com.crowdin.client.translations.model.ProjectBuildResponseList;
Expand Down Expand Up @@ -61,6 +62,10 @@ default String appendUrlParams(String url, Map<String, ? extends Optional> urlPa
value = DateTimeFormatter.ISO_INSTANT.format(((Date) entry.getValue().get()).toInstant());
} else {
value = entry.getValue().get().toString();
// free-text values may contain spaces or reserved characters
if (entry.getKey().equals("search") || entry.getKey().equals("filter") || entry.getKey().equals("croql")) {
value = RequestEncoder.encodeSpaces((String) value);
}
}
return entry.getKey() + "=" + value.toString();
})
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/crowdin/client/core/http/HttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ public void appendUrlParamsTest_dateIsFormattedAsIso8601() {
String urlWithParams = client.appendUrlParams(url, urlParams);
assertEquals(url + "?lastSeenFrom=2019-10-23T11:44:02Z", urlWithParams);
}

@Test
public void appendUrlParamsTest_freeTextParamsAreEncoded() {
String url = "test.com";
Map<String, Optional<Object>> urlParams = new LinkedHashMap<>();
urlParams.put("search", Optional.of("Q&A #1"));
urlParams.put("filter", Optional.of("a+b=100%"));
urlParams.put("croql", Optional.of("text contains \"x\""));
urlParams.put("orderBy", Optional.of("id%20desc"));
HttpClient client = new TestHttpClient();
String urlWithParams = client.appendUrlParams(url, urlParams);
assertEquals(url + "?search=Q%26A%20%231&filter=a%2Bb%3D100%25&croql=text%20contains%20%22x%22&orderBy=id%20desc", urlWithParams);
}
}
Loading