From c5486992058818122a717133fa04c10338e8555b Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 19 Oct 2023 23:37:46 +0200 Subject: [PATCH] Fix query param in UriBuilder Signed-off-by: jansupol --- .../java/org/glassfish/jersey/uri/UriTemplate.java | 2 +- .../e2e/common/uri/internal/JerseyUriBuilderTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java b/core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java index 003a4b2f9f..49bf77f46b 100644 --- a/core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java +++ b/core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java @@ -887,7 +887,7 @@ private static String createURI( offset, encode, mapValues, sb); if (sb.length() > sbLength) { char firstQuery = sb.charAt(sbLength); - if (firstQuery != '?' && firstQuery != '&') { + if (firstQuery != '?' && (query.trim().charAt(0) != '{' || firstQuery != '&')) { sb.insert(sbLength, '?'); } } diff --git a/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/uri/internal/JerseyUriBuilderTest.java b/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/uri/internal/JerseyUriBuilderTest.java index c5acb8845e..fddf1498be 100644 --- a/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/uri/internal/JerseyUriBuilderTest.java +++ b/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/uri/internal/JerseyUriBuilderTest.java @@ -1659,6 +1659,17 @@ public void testQueryParamStyleMultiPairs() { "key1=val1&key1=val2&key2=val1&key1=val3"); } + + @Test + public void testQueryParam() { + URI uri = new JerseyUriBuilder().scheme("http").host("localhost").port(8080).uri("some") + .replacePath("NewPath") + .replaceQuery("&Second") + .build(); + Assertions.assertEquals("&Second", uri.getQuery()); + } + + @Test void testFragment5269() throws URISyntaxException { final URI uri = new URI("http://www.example.org/foo.xml#xpointer(//Rube)").normalize();