Skip to content

Commit

Permalink
Fix parsing of portless IPv6 spring.rabbitmq.addresses
Browse files Browse the repository at this point in the history
Closes gh-28133
  • Loading branch information
wilkinsona committed Oct 1, 2021
1 parent 218bed1 commit a732933
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,14 +1083,15 @@ private String parseVirtualHost(String input) {
}

private void parseHostAndPort(String input, boolean sslEnabled) {
int portIndex = input.lastIndexOf(':');
if (portIndex == -1) {
int bracketIndex = input.lastIndexOf(']');
int colonIndex = input.lastIndexOf(':');
if (colonIndex == -1 || colonIndex < bracketIndex) {
this.host = input;
this.port = (determineSslEnabled(sslEnabled)) ? DEFAULT_PORT_SECURE : DEFAULT_PORT;
}
else {
this.host = input.substring(0, portIndex);
this.port = Integer.parseInt(input.substring(portIndex + 1));
this.host = input.substring(0, colonIndex);
this.port = Integer.parseInt(input.substring(colonIndex + 1));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ void customAddresses() {

@Test
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.determinePort()).isEqualTo(5672);
}
Expand Down

0 comments on commit a732933

Please sign in to comment.