Skip to content

Commit

Permalink
Fix normalizing URIs with percent encoded symbols
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and senivam committed Oct 12, 2023
1 parent 4f2b834 commit 313cc36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static URI normalize(final URI uri) {

final StringBuilder pathBuilder = new StringBuilder();
for (final String segment : resolvedSegments) {
pathBuilder.append('/').append(segment);
pathBuilder.append('/').append(UriComponent.encode(segment, UriComponent.Type.PATH));
}

String resultString = createURIWithStringValues(uri.getScheme(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriBuilder;
Expand Down Expand Up @@ -1659,12 +1660,19 @@ public void testQueryParamStyleMultiPairs() {
}

@Test
void testFragment2569() throws URISyntaxException {
void testFragment5269() throws URISyntaxException {
final URI uri = new URI("http://www.example.org/foo.xml#xpointer(//Rube)").normalize();
Assertions.assertEquals(uri, UriBuilder.fromUri(uri).build()); // prints "http://www.example.org/foo.xml#xpointer(//Rube)"
Assertions.assertEquals(uri, UriBuilder.fromUri(uri).fragment("xpointer(//{type})").build("Rube"));
}

@Test
public void test5416() {
URI uri = UriBuilder.fromUri("http://host.com/path%20path/.test.jpg").build();
Link link = Link.fromUri(uri).build();
Assertions.assertEquals(uri, link.getUri());
}

private void checkQueryFormat(String fromUri, JerseyQueryParamStyle queryParamStyle, String expected) {
final URI uri = ((JerseyUriBuilder) UriBuilder.fromUri(fromUri))
.setQueryParamStyle(queryParamStyle)
Expand Down

0 comments on commit 313cc36

Please sign in to comment.