Fix double encoding in DefaultApiVersionInserter

Ensure that the DefaultApiVersionInserter does not re-encode existing parts
of the input URI by using the 'encoded' flag in UriComponentsBuilder.

This prevents percent-encoded characters (like %20) from being incorrectly
double-encoded to %2520 during the version insertion process.

See gh-36097

Signed-off-by: Nabil Fawwaz Elqayyim <master@nabilfawwaz.com>
This commit is contained in:
Nabil Fawwaz Elqayyim
2026-01-09 15:06:07 +00:00
committed by rstoyanchev
parent 1370a833ed
commit e0db67aa3b
2 changed files with 54 additions and 1 deletions
@@ -33,6 +33,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* Default implementation of {@link ApiVersionInserter}.
*
* @author Rossen Stoyanchev
* @author Nabil Fawwaz Elqayyim
* @since 7.0
* @see DefaultApiVersionInserterBuilder
*/
@@ -81,7 +82,7 @@ final class DefaultApiVersionInserter implements ApiVersionInserter {
builder.replacePath(null);
pathSegments.forEach(builder::pathSegment);
}
return builder.build().toUri();
return builder.build(true).toUri();
}
private void assertPathSegmentIndex(Integer index, int pathSegmentsSize, URI uri) {