Skip to content

Commit 15c20c3

Browse files
committed
Fix regression with opaque URI determination
Before RfcUriParser we expected opaque URI's to not have ":/" after the scheme while the new parser expect opaque URI's to not have a slash anywhere after the scheme. This commit restores the previous behavior. Closes gh-34588
1 parent 5455c64 commit 15c20c3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -503,8 +503,7 @@ public void index(int index) {
503503
// Component capture
504504

505505
public InternalParser resolveIfOpaque() {
506-
boolean hasSlash = (this.uri.indexOf('/', this.index + 1) == -1);
507-
this.isOpaque = (hasSlash && !hierarchicalSchemes.contains(this.scheme));
506+
this.isOpaque = (this.uri.charAt(this.index) != '/' && !hierarchicalSchemes.contains(this.scheme));
508507
return this;
509508
}
510509

Diff for: spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -155,6 +155,19 @@ void fromOpaqueUri() {
155155
assertThat(result.toUri()).as("Invalid result URI").isEqualTo(uri);
156156
}
157157

158+
@ParameterizedTest // see gh-34588
159+
@EnumSource
160+
void fromOpaqueUriWithUrnScheme(ParserType parserType) {
161+
URI uri = UriComponentsBuilder
162+
.fromUriString("urn:text:service-{region}:{prefix}/{id}", parserType).build()
163+
.expand("US", "prefix1", "Id-2")
164+
.toUri();
165+
166+
assertThat(uri.getScheme()).isEqualTo("urn");
167+
assertThat(uri.isOpaque()).isTrue();
168+
assertThat(uri.getSchemeSpecificPart()).isEqualTo("text:service-US:prefix1/Id-2");
169+
}
170+
158171
@ParameterizedTest // see gh-9317
159172
@EnumSource
160173
void fromUriEncodedQuery(ParserType parserType) {

0 commit comments

Comments
 (0)