Skip to content

Commit

Permalink
Fix encoding for URIs that contain escaped sequences and a fragment
Browse files Browse the repository at this point in the history
Signed-off-by: Ehab Younes <ehab.alyounes@gmail.com>
  • Loading branch information
EhabY authored and szarnekow committed Mar 26, 2024
1 parent 1e42c1b commit 1d83f89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ public void test_withEmptyAuthority() throws Exception {
assertSame(uriWithAuthority, uriExtensions.withEmptyAuthority(uriWithAuthority));
}

@Test
public void testEscapedSequenceWithFragment() throws Exception {
assertEquals(URI.createURI("file:///path/to%20the/resource#ABC"),
uriExtensions.toUri(("file:///path/to%20the/resource#ABC")));
}

private Path createTempDir(final String prefix) throws Exception {
return Files.createTempDirectory(getTempDirPath(), prefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected URI cleanupEncodedCharacters(URI encoded) {
query = URI.encodeQuery(URI.decode(query), false);
}
if (fragment != null) {
query = URI.encodeFragment(URI.decode(fragment), false);
fragment = URI.encodeFragment(URI.decode(fragment), false);
}
// Depending on the shape of the URI recreate it from the decomposed parts which are now
// correctly encoded in a minimal (only the strictly necessary but no optional escape sequences) way
Expand Down

0 comments on commit 1d83f89

Please sign in to comment.