提交 b219c6ce 编写于 作者: R Rossen Stoyanchev

Adjust UriComponentsBuilder#toUriString behavior

Commit #93b7a4 added support for pre-configuring URI variables at the
UriComponentsBuilder level, and also changed toUriString to encode
template and URI variables separately. However this went a bit too far
causing side effects for URLs with curly braces that don't represent
URI variables.

This commit restores the original toUriString behavior which is to
encode template and URI variables sepraately only if URI variables have
been pre-configured.

Issue: SPR-17630
上级 17a41938
......@@ -441,7 +441,15 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
}
/**
* Build a URI String. This is a shortcut for:
* Build a URI String.
* <p>Effectively, a shortcut for building, encoding, and returning the
* String representation:
* <pre class="code">
* String uri = builder.build().encode().toUriString()
* </pre>
* <p>However if {@link #uriVariables(Map) URI variables} have been provided
* then the URI template is pre-encoded separately from URI variables (see
* {@link #encode()} for details), i.e. equivalent to:
* <pre>
* String uri = builder.encode().build().toUriString()
* </pre>
......@@ -449,7 +457,9 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
* @see UriComponents#toUriString()
*/
public String toUriString() {
return buildInternal(EncodingHint.ENCODE_TEMPLATE).toUriString();
return this.uriVariables.isEmpty() ?
encode().build().toUriString() :
buildInternal(EncodingHint.ENCODE_TEMPLATE).toUriString();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册