Commit 1b352baa authored by Chris Rohr's avatar Chris Rohr Committed by Greg Messner
Browse files

Added encoding to the tag name where the tag name is used in the url path (#372)

* Added encoding to the tag name where the tag name is used in the URL path
parent 38fe1c81
...@@ -94,7 +94,7 @@ public class TagsApi extends AbstractApi { ...@@ -94,7 +94,7 @@ public class TagsApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Tag getTag(Object projectIdOrPath, String tagName) throws GitLabApiException { public Tag getTag(Object projectIdOrPath, String tagName) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", tagName); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", urlEncode(tagName));
return (response.readEntity(Tag.class)); return (response.readEntity(Tag.class));
} }
...@@ -198,7 +198,7 @@ public class TagsApi extends AbstractApi { ...@@ -198,7 +198,7 @@ public class TagsApi extends AbstractApi {
*/ */
public void deleteTag(Object projectIdOrPath, String tagName) throws GitLabApiException { public void deleteTag(Object projectIdOrPath, String tagName) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", tagName); delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", urlEncode(tagName));
} }
/** /**
...@@ -215,7 +215,7 @@ public class TagsApi extends AbstractApi { ...@@ -215,7 +215,7 @@ public class TagsApi extends AbstractApi {
public Release createRelease(Object projectIdOrPath, String tagName, String releaseNotes) throws GitLabApiException { public Release createRelease(Object projectIdOrPath, String tagName, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("description", releaseNotes); Form formData = new GitLabApiForm().withParam("description", releaseNotes);
Response response = post(Response.Status.CREATED, formData.asMap(), Response response = post(Response.Status.CREATED, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", tagName, "release"); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", urlEncode(tagName), "release");
return (response.readEntity(Release.class)); return (response.readEntity(Release.class));
} }
...@@ -233,7 +233,8 @@ public class TagsApi extends AbstractApi { ...@@ -233,7 +233,8 @@ public class TagsApi extends AbstractApi {
public Release updateRelease(Object projectIdOrPath, String tagName, String releaseNotes) throws GitLabApiException { public Release updateRelease(Object projectIdOrPath, String tagName, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("description", releaseNotes); Form formData = new GitLabApiForm().withParam("description", releaseNotes);
Response response = put(Response.Status.OK, formData.asMap(), Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", tagName, "release"); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", urlEncode(tagName), "release");
return (response.readEntity(Release.class)); return (response.readEntity(Release.class));
} }
} }
...@@ -23,6 +23,7 @@ public class TestTagsApi extends AbstractIntegrationTest { ...@@ -23,6 +23,7 @@ public class TestTagsApi extends AbstractIntegrationTest {
private static final String TEST_TAG_NAME_1 = "test-tag-1"; private static final String TEST_TAG_NAME_1 = "test-tag-1";
private static final String TEST_TAG_NAME_0 = "test-tag-0"; private static final String TEST_TAG_NAME_0 = "test-tag-0";
private static final String TEST_TAG_WITH_SLASH = "env/test-tag";
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static Project testProject; private static Project testProject;
...@@ -46,6 +47,10 @@ public class TestTagsApi extends AbstractIntegrationTest { ...@@ -46,6 +47,10 @@ public class TestTagsApi extends AbstractIntegrationTest {
try { try {
gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_NAME_1); gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_NAME_1);
} catch (Exception ignore) {} } catch (Exception ignore) {}
try {
gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_WITH_SLASH);
} catch (Exception ignore) {}
} }
} }
...@@ -59,6 +64,10 @@ public class TestTagsApi extends AbstractIntegrationTest { ...@@ -59,6 +64,10 @@ public class TestTagsApi extends AbstractIntegrationTest {
try { try {
gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_NAME_1); gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_NAME_1);
} catch (Exception ignore) {} } catch (Exception ignore) {}
try {
gitLabApi.getTagsApi().deleteTag(testProject, TEST_TAG_WITH_SLASH);
} catch (Exception ignore) {}
} }
} }
...@@ -127,4 +136,15 @@ public class TestTagsApi extends AbstractIntegrationTest { ...@@ -127,4 +136,15 @@ public class TestTagsApi extends AbstractIntegrationTest {
assertTrue(tags.getTotalItems() > 0); assertTrue(tags.getTotalItems() > 0);
assertTrue(tags.stream().map(Tag::getName).anyMatch(s -> TEST_TAG_NAME_0.equals(s))); assertTrue(tags.stream().map(Tag::getName).anyMatch(s -> TEST_TAG_NAME_0.equals(s)));
} }
@Test
public void testGetTagWithSpecialCharacersInTagName() throws GitLabApiException {
Tag testTag = gitLabApi.getTagsApi().createTag(testProject, TEST_TAG_WITH_SLASH, "master");
assertNotNull(testTag);
assertEquals(TEST_TAG_WITH_SLASH, testTag.getName());
testTag = gitLabApi.getTagsApi().getTag(testProject, TEST_TAG_WITH_SLASH);
assertNotNull(testTag);
assertEquals(TEST_TAG_WITH_SLASH, testTag.getName());
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment