Skip to content
This repository was archived by the owner on Apr 16, 2022. It is now read-only.

Commit 51ef521

Browse files
committed
URI-encode spaces in URLs
1 parent b55a171 commit 51ef521

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/org/opendatakit/briefcase/reused/http/Request.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public RequestMethod getMethod() {
8383
// TODO v2.0 Move this to RequestBuilder, with uri() and isUri()
8484
URI asUri() {
8585
try {
86-
return url.toURI();
86+
return new URI(url.toString().replaceAll(" ", "%20"));
8787
} catch (URISyntaxException e) {
8888
throw new BriefcaseException(e);
8989
}

test/java/org/opendatakit/briefcase/reused/http/RequestTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package org.opendatakit.briefcase.reused.http;
1818

1919
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static org.hamcrest.Matchers.containsString;
2021
import static org.hamcrest.Matchers.instanceOf;
2122
import static org.hamcrest.Matchers.is;
23+
import static org.hamcrest.Matchers.not;
2224
import static org.junit.Assert.assertThat;
2325

2426
import java.io.ByteArrayInputStream;
@@ -28,6 +30,7 @@
2830
public class RequestTest {
2931

3032
private static final String BASE_URL = "http://foo.com";
33+
private static final String URL_WITH_SPACE = "http://foo.com/some spaces are here";
3134

3235
@Test
3336
public void can_map_a_response_body() {
@@ -40,4 +43,10 @@ public void can_map_a_response_body() {
4043
public void can_return_its_uri() {
4144
assertThat(RequestBuilder.get(BASE_URL).build().asUri(), instanceOf(URI.class));
4245
}
46+
47+
@Test
48+
public void can_return_its_uri_with_encoded_spaces() {
49+
assertThat(RequestBuilder.get(URL_WITH_SPACE).build().asUri(), instanceOf(URI.class));
50+
assertThat(RequestBuilder.get(URL_WITH_SPACE).build().asUri().toString(), not(containsString(" ")));
51+
}
4352
}

0 commit comments

Comments
 (0)