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

Fix normalizing URIs with percent encoded symbols #5417

Merged
merged 1 commit into from
Oct 12, 2023
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 @@ -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