From: Daniela Petruzalek Date: Wed, 4 Jan 2023 15:26:03 +0000 (+0000) Subject: os: fix findOneDriveDir to expand strings that contain environment variables X-Git-Tag: go1.21rc1~1752 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1eb37facdd20f28666363057dd51459aa6dd44a7;p=gostls13.git os: fix findOneDriveDir to expand strings that contain environment variables On Windows the registry data type REG_EXPAND_SZ indicates that the string requires expansion of environment variables. The existing implementation doesn't take that into consideration and just returns the unexpanded string, ignoring the registry type. This implementation ensures that environment variables are properly expanded when needed. Fixes #57576 Change-Id: Ia02c1b05a4cf6eaaffb3be88ce1c9ee100db250f Reviewed-on: https://go-review.googlesource.com/c/go/+/460535 Auto-Submit: Bryan Mills Reviewed-by: Dmitri Shuralyov Run-TryBot: Bryan Mills Reviewed-by: Alex Brainman Reviewed-by: Quim Muntal Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index 1133639105..21a8c21d1e 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -872,10 +872,19 @@ func findOneDriveDir() (string, error) { } defer k.Close() - path, _, err := k.GetStringValue("UserFolder") + path, valtype, err := k.GetStringValue("UserFolder") if err != nil { return "", fmt.Errorf("reading UserFolder failed: %v", err) } + + if valtype == registry.EXPAND_SZ { + expanded, err := registry.ExpandString(path) + if err != nil { + return "", fmt.Errorf("expanding UserFolder failed: %v", err) + } + path = expanded + } + return path, nil }