Skip to content

Commit

Permalink
Fix IllegalArgumentException if scheme contains but not starts with U…
Browse files Browse the repository at this point in the history
…RI variable

See spring-projectsGH-33699, Continue of c261ca3
  • Loading branch information
quaff committed Oct 16, 2024
1 parent c261ca3 commit 57d29b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Parser for URI's based on RFC 3986 syntax.
*
* @author Rossen Stoyanchev
* @author Yanming Zhou
* @since 6.2
*
* @see <a href="https://www.rfc-editor.org/info/rfc3986">RFC 3986</a>
Expand Down Expand Up @@ -510,7 +511,7 @@ public InternalParser resolveIfOpaque() {

public InternalParser captureScheme() {
String scheme = captureComponent("scheme");
this.scheme = (!scheme.startsWith("{") ? scheme.toLowerCase(Locale.ROOT) : scheme);
this.scheme = (!scheme.contains("{") ? scheme.toLowerCase(Locale.ROOT) : scheme);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @author Juergen Hoeller
* @author Sam Brannen
* @author David Eckel
* @author Yanming Zhou
*/
class UriComponentsBuilderTests {

Expand Down Expand Up @@ -637,6 +638,24 @@ void schemeVariableMixedCase(ParserType parserType) {
.buildAndExpand(Map.of("TheScheme", "ws"))
.toUri();
assertThat(uri.toString()).isEqualTo("ws://example.org");

uri = UriComponentsBuilder
.fromUriString("{TheScheme}s://example.org", parserType)
.buildAndExpand(Map.of("TheScheme", "ws"))
.toUri();
assertThat(uri.toString()).isEqualTo("wss://example.org");

uri = UriComponentsBuilder
.fromUriString("s{TheScheme}://example.org", parserType)
.buildAndExpand(Map.of("TheScheme", "ws"))
.toUri();
assertThat(uri.toString()).isEqualTo("sws://example.org");

uri = UriComponentsBuilder
.fromUriString("s{TheScheme}s://example.org", parserType)
.buildAndExpand(Map.of("TheScheme", "ws"))
.toUri();
assertThat(uri.toString()).isEqualTo("swss://example.org");
}

@ParameterizedTest
Expand Down

0 comments on commit 57d29b0

Please sign in to comment.