Skip to content

Commit

Permalink
Support queries in opaque URLs
Browse files Browse the repository at this point in the history
Closes gh-32920
  • Loading branch information
poutsma committed Jun 7, 2024
1 parent 7fc4937 commit 35e8f1c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public static UriComponentsBuilder fromUriString(String uri) throws InvalidUrlEx
builder.port(urlRecord.port().toString());
}
if (urlRecord.path().isOpaque()) {
builder.schemeSpecificPart(urlRecord.path().toString());
String ssp = urlRecord.path() + urlRecord.search();
builder.schemeSpecificPart(ssp);
}
else {
builder.path(urlRecord.path().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ void fromUriString() {
assertThat(result.getQuery()).isNull();
assertThat(result.getFragment()).isEqualTo("baz");

result = UriComponentsBuilder.fromUriString("mailto:user@example.com?subject=foo").build();
assertThat(result.getScheme()).isEqualTo("mailto");
assertThat(result.getUserInfo()).isNull();
assertThat(result.getHost()).isNull();
assertThat(result.getPort()).isEqualTo(-1);
assertThat(result.getSchemeSpecificPart()).isEqualTo("user@example.com?subject=foo");
assertThat(result.getPath()).isNull();
assertThat(result.getQuery()).isNull();
assertThat(result.getFragment()).isNull();

result = UriComponentsBuilder.fromUriString("docs/guide/collections/designfaq.html#28").build();
assertThat(result.getScheme()).isNull();
assertThat(result.getUserInfo()).isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,31 @@ private void testParse(String input, String scheme, @Nullable String host, @Null
else {
assertThat(result.port()).as("Port is not null").isNull();
}
assertThat(result.hasOpaquePath()).as("Result has opaque path").isFalse();
assertThat(result.path().toString()).as("Invalid path").isEqualTo(path);
assertThat(result.query()).as("Invalid query").isEqualTo(query);
assertThat(result.fragment()).as("Invalid fragment").isEqualTo(fragment);
}

@Test
void parseOpaque() {
testParseOpaque("mailto:user@example.com?subject=foo", "user@example.com", "subject=foo");

}

void testParseOpaque(String input, String path, @Nullable String query) {
UrlParser.UrlRecord result = UrlParser.parse("mailto:user@example.com?subject=foo", EMPTY_URL_RECORD, null, null);


assertThat(result.scheme()).as("Invalid scheme").isEqualTo("mailto");
assertThat(result.hasOpaquePath()).as("Result has no opaque path").isTrue();
assertThat(result.path().toString()).as("Invalid path").isEqualTo(path);
if (query != null) {
assertThat(result.query()).as("Query is null").isNotNull();
assertThat(result.query()).as("Invalid query").isEqualTo(query);
}
else {
assertThat(result.query()).as("Query is not null").isNull();
}
}
}

0 comments on commit 35e8f1c

Please sign in to comment.