Skip to content

Commit

Permalink
TDD: spaces need to be encoded as %20
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli Dagenais committed Sep 16, 2016
1 parent 4959e17 commit 0cfe653
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tfs/src/main/java/hudson/plugins/tfs/util/UriHelper.java
Expand Up @@ -226,7 +226,9 @@ public static URI join(final String collectionUrl, final Object... components) {
}
try {
final String encodedComponent = URLEncoder.encode(component.toString(), UTF_8);
sb.append(encodedComponent);
// URLEncoder#encode() encodes spaces as "+" but they should be "%20"
final String correctlyEncodedComponent = encodedComponent.replaceAll("\\+", "%20");
sb.append(correctlyEncodedComponent);
}
catch (final UnsupportedEncodingException e) {
throw new Error(e);
Expand Down
4 changes: 2 additions & 2 deletions tfs/src/test/java/hudson/plugins/tfs/util/UriHelperTest.java
Expand Up @@ -302,9 +302,9 @@ private static void areSameGitRepo(final String a, final String b, final boolean
@Test public void join_urlEncoding() throws Exception {
final String collectionUrl = "https://fabrikam-fiber-inc.visualstudio.com/";

final URI actual = UriHelper.join(collectionUrl, "_git", "Repo Name With Spaces");
final URI actual = UriHelper.join(collectionUrl, "_git", "Repo Name+With Spaces");

Assert.assertEquals(URI.create("https://fabrikam-fiber-inc.visualstudio.com/_git/Repo+Name+With+Spaces"), actual);
Assert.assertEquals(URI.create("https://fabrikam-fiber-inc.visualstudio.com/_git/Repo%20Name%2BWith%20Spaces"), actual);
}

@Test public void join_sampleApiCall() throws Exception {
Expand Down

0 comments on commit 0cfe653

Please sign in to comment.