cmd/go: fix TestScript/govcs

On my Mac, TestScript/govcs was failing because hg prints a URL
using 1.0.0.127.in-addr.arpa instead of 127.0.0.1, and my Mac
cannot resolve that name back into an IP address.

% host 127.0.0.1
1.0.0.127.in-addr.arpa domain name pointer localhost.
% host 1.0.0.127.in-addr.arpa
%

Change-Id: Ia0762342d5926d13d786fe66de40590dc8977ff5
Reviewed-on: https://go-review.googlesource.com/c/go/+/718184
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Russ Cox 2025-11-05 14:46:35 -05:00 committed by Gopher Robot
parent daa220a1c9
commit 28f1ad5782

View file

@ -109,6 +109,13 @@ func (h *hgHandler) Handler(dir string, env []string, logger *log.Logger) (http.
wg.Done()
}()
// On some systems,
// hg serve --address=localhost --print-url prints in-addr.arpa hostnames
// even though they cannot be looked up.
// Replace them with IP literals.
line = strings.ReplaceAll(line, "//1.0.0.127.in-addr.arpa", "//127.0.0.1")
line = strings.ReplaceAll(line, "//1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", "//[::1]")
u, err := url.Parse(strings.TrimSpace(line))
if err != nil {
logger.Printf("%v: %v", cmd, err)