Skip to content

path/filepath: Clean removes ending slash for volume on Windows in Go 1.21.4 #64028

Closed
@calmh

Description

@calmh

Go 1.21.4 fixed a problem in filepath.Clean regarding \??\ paths. However, it also removed the ending slash for volumes in \\?\ paths. Is this expected? The docs still state

The returned path ends in a slash only if it represents a root directory, such as "/" on Unix or C:\ on Windows.

The following test passes on Go 1.21.3.

func TestFilepathClean(t *testing.T) {
	cases := []struct {
		in  string
		out string
	}{
		{`C:\`, `C:\`},
		{`\\?\C:\`, `\\?\C:\`},
	}
	for _, c := range cases {
		if out := filepath.Clean(c.in); out != c.out {
			t.Errorf("filepath.Clean(%s) => %s expected %s", c.in, out, c.out)
		}
	}
}

On Go 1.21.4 this happens:

PS C:\Users\jb\dev\syncthing\lib\fs> go1.21.4 test -run FilepathClean
--- FAIL: TestFilepathClean (0.00s)
    basicfs_windows_test.go:30: filepath.Clean(\\?\C:\) => \\?\C: expected \\?\C:\
FAIL
exit status 1
FAIL    github.com/syncthing/syncthing/lib/fs   0.062s

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions