aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath/path_test.go
diff options
context:
space:
mode:
authormatsuyoshi30 <sfbgwm30@gmail.com>2023-01-19 00:45:18 +0900
committerGopher Robot <gobot@golang.org>2023-01-20 22:42:39 +0000
commit0518e33f6c0c3a9f6ce1f800ca4b7fe5f3a1b7a5 (patch)
tree6c73cd4bfc388818c97729b31f7a8f848f890b66 /src/path/filepath/path_test.go
parent27b6ace2b4b068905eb2963e656e3cefcba32222 (diff)
downloadgo-0518e33f6c0c3a9f6ce1f800ca4b7fe5f3a1b7a5.tar.xz
path/filepath: fix evaluation of symlinks to paths under /tmp on macOS
For symlinks created from symlinks under the root directory created as the relative path (e.g., symbolic links under /tmp), we update vol and volLen. Fixes #57905 Change-Id: I45affd1db3b93109de51bf19b181f3cdba061109 Reviewed-on: https://go-review.googlesource.com/c/go/+/461761 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/path/filepath/path_test.go')
-rw-r--r--src/path/filepath/path_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index 6647444852..e6a9270909 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -1193,6 +1193,37 @@ func TestIssue13582(t *testing.T) {
}
}
+// Issue 57905.
+func TestRelativeSymlinkToAbsolute(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+ // Not parallel: uses os.Chdir.
+
+ tmpDir := t.TempDir()
+ chdir(t, tmpDir)
+
+ // Create "link" in the current working directory as a symlink to an arbitrary
+ // absolute path. On macOS, this path is likely to begin with a symlink
+ // itself: generally either in /var (symlinked to "private/var") or /tmp
+ // (symlinked to "private/tmp").
+ if err := os.Symlink(tmpDir, "link"); err != nil {
+ t.Fatal(err)
+ }
+ t.Logf(`os.Symlink(%q, "link")`, tmpDir)
+
+ p, err := filepath.EvalSymlinks("link")
+ if err != nil {
+ t.Fatalf(`EvalSymlinks("link"): %v`, err)
+ }
+ want, err := filepath.EvalSymlinks(tmpDir)
+ if err != nil {
+ t.Fatalf(`EvalSymlinks(%q): %v`, tmpDir, err)
+ }
+ if p != want {
+ t.Errorf(`EvalSymlinks("link") = %q; want %q`, p, want)
+ }
+ t.Logf(`EvalSymlinks("link") = %q`, p)
+}
+
// Test directories relative to temporary directory.
// The tests are run in absTestDirs[0].
var absTestDirs = []string{