Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

JerseyUriBuilder: allow template parameter regexes to contain braces #3797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -285,7 +285,7 @@ public static String encodeTemplateNames(String s) {

private static String _encode(final String s, final Type t, final boolean template, final boolean contextualEncode) {
final boolean[] table = ENCODING_TABLES[t.ordinal()];
boolean insideTemplateParam = false;
int templateParamDepth = 0;

StringBuilder sb = null;
for (int offset = 0, codePoint; offset < s.length(); offset += Character.charCount(codePoint)) {
Expand All @@ -299,12 +299,12 @@ private static String _encode(final String s, final Type t, final boolean templa
if (template) {
boolean leavingTemplateParam = false;
if (codePoint == '{') {
insideTemplateParam = true;
++templateParamDepth;
} else if (codePoint == '}') {
insideTemplateParam = false;
--templateParamDepth;
leavingTemplateParam = true;
}
if (insideTemplateParam || leavingTemplateParam) {
if (templateParamDepth > 0 || leavingTemplateParam) {
if (sb != null) {
sb.append(Character.toChars(codePoint));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MultivaluedMap;
Expand Down Expand Up @@ -1068,6 +1070,10 @@ public String get() {
public Object locator() {
return null;
}

@PUT
@Path("complex/{id3: \\p{XDigit}{8}(?:-\\p{XDigit}{4}){3}-\\p{XDigit}{12}}")
public void put() {}
}

@Test
Expand All @@ -1082,6 +1088,11 @@ public void testResourceWithTemplateRegexAppendPath() throws NoSuchMethodExcepti
final Method locator = ResourceWithTemplateRegex.class.getMethod("locator");
ub = UriBuilder.fromUri("http://localhost:8080/base").path(get).path(locator).build("foo", "bar");
Assert.assertEquals(URI.create("http://localhost:8080/base/method/foo/locator/bar"), ub);

final Method put = ResourceWithTemplateRegex.class.getMethod("put");
final UUID uuid = UUID.randomUUID();
ub = UriBuilder.fromUri("http://localhost:8080/base").path(put).build(uuid);
Assert.assertEquals(URI.create("http://localhost:8080/base/complex/" + uuid), ub);
}

interface GenericInterface<T, U> {
Expand Down