Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change url path encoding to match jersey decoding #2693

Merged
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
10 changes: 2 additions & 8 deletions clients/java/src/main/java/marquez/client/MarquezPathV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
package marquez.client;

import com.google.common.annotations.VisibleForTesting;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import com.google.common.net.UrlEscapers;
import java.util.Arrays;
import java.util.Iterator;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -57,11 +55,7 @@ Converts path template (prepended with BASE_PATH), where path parts are separate
}

static String encode(String input) {
try {
return URLEncoder.encode(input, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
throw new MarquezClientException(e);
}
return UrlEscapers.urlPathSegmentEscaper().escape(input);
}

static String listNamespacesPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testClient_preservesBaseURL() throws Exception {
public void testClient_properlyFormatsNamespaces() throws Exception {
final String pathTemplate = "/namespaces/%s";
final String pathArg = "database://localhost:1234";
final String path = "/namespaces/database%3A%2F%2Flocalhost%3A1234";
final String path = "/namespaces/database:%2F%2Flocalhost:1234";

URL expected = new URL(BASE_URL + BASE_PATH + path);
URL actual = marquezUrl.from(path(pathTemplate, pathArg));
Expand Down
25 changes: 17 additions & 8 deletions clients/java/src/test/java/marquez/client/MarquezPathV1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@ void testPath_namespaceUrl(String expected, String namespaceName) {

private static Stream<Arguments> testPath_namespaceUrl() {
return Stream.of(
Arguments.of("/api/v1/namespaces/s3%3A%2F%2Fbucket", "s3://bucket"),
Arguments.of("/api/v1/namespaces/bigquery%3A", "bigquery:"),
Arguments.of("/api/v1/namespaces/s3:%2F%2Fbucket", "s3://bucket"),
Arguments.of("/api/v1/namespaces/bigquery:", "bigquery:"),
Arguments.of("/api/v1/namespaces/usual-namespace-name", "usual-namespace-name"),
Arguments.of("/api/v1/namespaces/a%3A%5C%3Aa", "a:\\:a"));
Arguments.of("/api/v1/namespaces/a:%5C:a", "a:\\:a"));
}

@Test
void testPath_datasetUrl() {
Assertions.assertEquals(
"/api/v1/namespaces/s3%3A%2F%2Fbuckets/datasets/source-file.json",
MarquezPathV1.datasetPath("s3://buckets", "source-file.json"));
@ParameterizedTest
@MethodSource
void testPath_datasetUrl(String expected, String namespaceName, String datasetName) {
Assertions.assertEquals(expected, MarquezPathV1.datasetPath(namespaceName, datasetName));
}

private static Stream<Arguments> testPath_datasetUrl() {
return Stream.of(
Arguments.of(
"/api/v1/namespaces/s3:%2F%2Fbucket/datasets/source-file.json",
"s3://bucket", "source-file.json"),
Arguments.of(
"/api/v1/namespaces/snowflake:%2F%2Faccount/datasets/DATABASE.SCHEMA.%22Exotic%20Table%20Name!%22",
"snowflake://account", "DATABASE.SCHEMA.\"Exotic Table Name!\""));
}

@Test
Expand Down
Loading