ipv6-regression-fix

This should (may) finish fixing the regressions caused by earlier IPv6 fixes. Some environments did not tolerate having the brackets around anything that wasn't an IPv6 address.

It looks to me like a clean and reliable way to ensure that the brackets get added only to IPv6 addresses and not IPv4 addresses or hostnames, but I'm open to input and certainly more testing.
DRY: This should be split up into a helper function.