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

Support templating params as 'host' of Uri #54

Merged
merged 1 commit into from
Oct 18, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getMethod() {
* in the URI, it will only show up once in the set.
*/
private static Set<String> parsePathParameters(DeepLinkUri uri) {
Matcher matcher = Pattern.compile(PARAM_REGEX).matcher(uri.encodedPath());
Matcher matcher = Pattern.compile(PARAM_REGEX).matcher(uri.encodedHost() + uri.encodedPath());
Set<String> patterns = new LinkedHashSet<>();
while (matcher.find()) {
patterns.add(matcher.group(1));
Expand Down Expand Up @@ -108,6 +108,6 @@ boolean matches(String inputUri) {
}

private String schemeHostAndPath(DeepLinkUri uri) {
return uri.scheme() + "://" + uri.host() + parsePath(uri);
return uri.scheme() + "://" + uri.encodedHost() + parsePath(uri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ String host() {
return host;
}

String encodedHost() {
return canonicalize(host, DeepLinkUri.CONVERT_TO_URI_ENCODE_SET, true, true);
}

/**
* Returns the explicitly-specified port if one was provided, or the default port for this URL's
* scheme. For example, this returns 8443 for {@code https://square.com:8443/} and 443 for {@code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

public class DeepLinkEntryTest {
@Test public void testSingleParam() {
Expand Down Expand Up @@ -93,6 +94,15 @@ public class DeepLinkEntryTest {
assertThat(entry.matches("jackson5://example.com")).isTrue();
}

@Test public void multiplePathParams() {
DeepLinkEntry entry = deepLinkEntry("airbnb://{foo}/{bar}");

Map<String, String> parameters = entry.getParameters("airbnb://baz/qux");
assertThat(parameters)
.hasSize(2)
.contains(entry("foo", "baz"), entry("bar", "qux"));
}

private static DeepLinkEntry deepLinkEntry(String uri) {
return new DeepLinkEntry(uri, DeepLinkEntry.Type.CLASS, String.class, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public class DeepLinkRegistryTest {
assertThat(registry.parseUri("http://test/12345/alice")).isNotNull();
}

@Test public void testHostParameter() {
registry.registerDeepLink(
"http://{param1}", DeepLinkEntry.Type.CLASS, String.class, null);

assertThat(registry.parseUri("http://test")).isNotNull();
}

@Test public void testEntryNotFound() {
registry.registerDeepLink(
"http://test/{param1}/{param2}", DeepLinkEntry.Type.CLASS, String.class, null);
Expand Down