The fix for gh-26905 introduced an unintended behavior change for some ambiguous URL patterns:

URI uri = UriComponentsBuilder
                .fromUriString("ws://localhost:{port}{path}")
                .buildAndExpand(7777, "/test")
                .toUri();

// Now fails because it's parsing "7777/test" as an integer port value.

While the fix for gh-26905 better warns against invalid port values, it now fails for ambiguous patterns and matches more than expected if a "/" is not present before variable expansion. We should refine the PORT_PATTERN and ensure that such use cases are still working.