rabbitmq-nio icon indicating copy to clipboard operation
rabbitmq-nio copied to clipboard

Ending up with double "//" in vhost when using Swift 6

Open xtremekforever opened this issue 6 months ago • 0 comments

This appears to be a bug that has arisen from using Swift 6.0 now. This block of code in AMQPConnectionConfiguration is adding a second / character to the vhost, since the first line is apparently populating the vhost string with a first / character:

        var vhost = url.path.isEmpty ? nil : String(url.path.removingPercentEncoding?.dropFirst() ?? "")

        // workaround: "/%f" is interpreted as / by URL (this restores %f as /)
        if url.absoluteString.lowercased().hasSuffix("%2f") {
            if let vh = vhost  {
                vhost = vh + "/"
            } else {
                vhost = "/"
            }
        }

So if I use a URL of amqp://guest:guest@localhost/%2f for example, now I get the following error in Swift 6:

connectionClosed(replyCode: Optional(530), replyText: Optional("NOT_ALLOWED - vhost // not found"))

I think that perhaps the workaround block can be condensed to this:

        if url.absoluteString.lowercased().hasSuffix("%2f") {
            vhost = "/"
        }

To avoid having the vhost with two // characters in it.

xtremekforever avatar Aug 01 '24 14:08 xtremekforever