String manipulation like this seems fragile. Considering using `java.net.URI` instead.