mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Fix parsing of portless IPv6 spring.rabbitmq.addresses
Closes gh-28133
This commit is contained in:
parent
218bed1f8e
commit
a73293350a
@ -1083,14 +1083,15 @@ public class RabbitProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void parseHostAndPort(String input, boolean sslEnabled) {
|
private void parseHostAndPort(String input, boolean sslEnabled) {
|
||||||
int portIndex = input.lastIndexOf(':');
|
int bracketIndex = input.lastIndexOf(']');
|
||||||
if (portIndex == -1) {
|
int colonIndex = input.lastIndexOf(':');
|
||||||
|
if (colonIndex == -1 || colonIndex < bracketIndex) {
|
||||||
this.host = input;
|
this.host = input;
|
||||||
this.port = (determineSslEnabled(sslEnabled)) ? DEFAULT_PORT_SECURE : DEFAULT_PORT;
|
this.port = (determineSslEnabled(sslEnabled)) ? DEFAULT_PORT_SECURE : DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.host = input.substring(0, portIndex);
|
this.host = input.substring(0, colonIndex);
|
||||||
this.port = Integer.parseInt(input.substring(portIndex + 1));
|
this.port = Integer.parseInt(input.substring(colonIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,14 @@ class RabbitPropertiesTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ipv6Address() {
|
void ipv6Address() {
|
||||||
this.properties.setAddresses("amqp://foo:bar@[aaaa:bbbb:cccc::d]:5672");
|
this.properties.setAddresses("amqp://foo:bar@[aaaa:bbbb:cccc::d]:1234");
|
||||||
|
assertThat(this.properties.determineHost()).isEqualTo("[aaaa:bbbb:cccc::d]");
|
||||||
|
assertThat(this.properties.determinePort()).isEqualTo(1234);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ipv6AddressDefaultPort() {
|
||||||
|
this.properties.setAddresses("amqp://foo:bar@[aaaa:bbbb:cccc::d]");
|
||||||
assertThat(this.properties.determineHost()).isEqualTo("[aaaa:bbbb:cccc::d]");
|
assertThat(this.properties.determineHost()).isEqualTo("[aaaa:bbbb:cccc::d]");
|
||||||
assertThat(this.properties.determinePort()).isEqualTo(5672);
|
assertThat(this.properties.determinePort()).isEqualTo(5672);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user