Skip to content

Decode encoded AMQP URI values when no port is specified in spring-boot-amqp-rabbitmq #52818

Closed as not planned

Description

@manthansharma6767

In module/spring-boot-amqp-rabbitmq, RabbitUri.of(String) does not decode URL-encoded values (username, password, and virtual host) if no port is explicitly specified in the URI.

Lines 106-110 of module/spring-boot-amqp-rabbitmq/src/main/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/RabbitUri.java:

int bracketIndex = connection.lastIndexOf(']');
int colonIndex = connection.lastIndexOf(':');
if (colonIndex == -1 || colonIndex < bracketIndex) {
    return new RabbitUri(secure, connection, null, username, password, virtualHost);
}

When a port is specified, decode(...) is called on line 114, but when no port is specified, raw encoded values like us%3Aer or p%40ss are returned.

This issue was previously resolved for module/spring-boot-rabbitmq in gh-52644, but module/spring-boot-amqp-rabbitmq was not updated to match.

Additionally, in module/spring-boot-amqp-rabbitmq/src/test/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/RabbitUriTests.java, the test method determineVirtualHostWhenHasNoUserDefinedVirtualHost contains a copy-paste assertion checking determinePassword instead of determineVirtualHost.

Steps to Reproduce

Parse a URI without a port containing encoded characters:

RabbitUri uri = RabbitUri.of("amqp://us%3Aer:p%40ss@localhost/my%2Fvhost");
// Currently produces username "us%3Aer", password "p%40ss", and virtual host "my%2Fvhost"
// Expected: username "us:er", password "p@ss", and virtual host "my/vhost"

Suggested Fix

  1. Update RabbitUri.java in module/spring-boot-amqp-rabbitmq to return decoded values when no port is specified:
if (colonIndex == -1 || colonIndex < bracketIndex) {
    return new RabbitUri(secure, connection, null, decode(username), decode(password), decode(virtualHost));
}
  1. Add unit tests in RabbitUriTests.java covering port-less URIs with encoded credentials and virtual hosts, and fix the assertion in determineVirtualHostWhenHasNoUserDefinedVirtualHost.

I would like to work on this issue and submit a PR.

Activity

  1. philwebb commented on Nov 16, 2026

    @philwebb
    Member

    Closing in favor of PR #52819. Thanks @manthansharma6767!

  2. added
    status: supersededAn issue that has been superseded by another
    and removed
    status: waiting-for-triageAn issue that has not yet been triaged. Contributions will not be accepted.
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions