File tree 2 files changed +8
-8
lines changed
main/java/org/springframework/web/util
test/java/org/springframework/web/util
2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -485,7 +485,7 @@ public String toUriString() {
485
485
if (this .host != null ) {
486
486
uriBuilder .append (this .host );
487
487
}
488
- if (getPort () != - 1 ) {
488
+ if (StringUtils . hasText ( this . port ) && ! this . port . equals ( "-1" ) ) {
489
489
uriBuilder .append (':' ).append (this .port );
490
490
}
491
491
}
Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ void toUriWithIpv6HostAlreadyEncoded() {
101
101
URI .create ("http://[1abc:2abc:3abc::5ABC:6abc]:8080/hotel%20list/Z%C3%BCrich" ));
102
102
}
103
103
104
+ @ Test
105
+ void toUriStringWithPortVariable () {
106
+ String url = "http://localhost:{port}/first" ;
107
+ assertThat (UriComponentsBuilder .fromUriString (url ).build ().toUriString ()).isEqualTo (url );
108
+ }
109
+
104
110
@ Test
105
111
void expand () {
106
112
UriComponents uri = UriComponentsBuilder .fromUriString ("https://example.com" ).path ("/{foo} {bar}" ).build ();
@@ -166,12 +172,6 @@ private void assertExceptionsForInvalidPort(UriComponents uriComponents) {
166
172
assertThatIllegalStateException ()
167
173
.isThrownBy (uriComponents ::toUri )
168
174
.withMessage ("The port must be an integer: XXX" );
169
- assertThatIllegalStateException ()
170
- .isThrownBy (uriComponents ::toUriString )
171
- .withMessage ("The port must be an integer: XXX" );
172
- assertThatIllegalStateException ()
173
- .isThrownBy (uriComponents ::toString )
174
- .withMessage ("The port must be an integer: XXX" );
175
175
}
176
176
177
177
@ Test
You can’t perform that action at this time.
0 commit comments