mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
cbd828e190
- Encode cwd via new encodeCwdForDir helper that handles both `/` and `\` separators and strips characters illegal in Windows directory names (`: < > " | ? *`) - Fixes session creation on Windows where the drive-letter colon produced names like `C:--test` and caused mkdir to fail - Add regression tests covering Unix paths, Windows drive roots, secondary drives, mixed separators, and other illegal chars Fixes #18
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package session
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestEncodeCwdForDir verifies the working-directory → session-directory
|
|
// name encoding strips characters that are illegal on Windows (notably the
|
|
// drive-letter colon, see issue #18) while preserving the previous output
|
|
// for the typical Unix paths.
|
|
func TestEncodeCwdForDir(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cwd string
|
|
want string
|
|
}{
|
|
{
|
|
name: "unix absolute path",
|
|
cwd: "/home/user/proj",
|
|
want: "home--user--proj",
|
|
},
|
|
{
|
|
name: "unix relative path",
|
|
cwd: "proj/sub",
|
|
want: "proj--sub",
|
|
},
|
|
{
|
|
name: "windows drive root",
|
|
cwd: `C:\test`,
|
|
want: "C--test",
|
|
},
|
|
{
|
|
name: "windows nested path",
|
|
cwd: `C:\Users\User\code`,
|
|
want: "C--Users--User--code",
|
|
},
|
|
{
|
|
name: "windows secondary drive",
|
|
cwd: `S:\work\repo`,
|
|
want: "S--work--repo",
|
|
},
|
|
{
|
|
name: "windows mixed separators",
|
|
cwd: `C:\Users/User\code`,
|
|
want: "C--Users--User--code",
|
|
},
|
|
{
|
|
name: "windows other illegal chars stripped",
|
|
cwd: `C:\a<b>c|d?e*f"g`,
|
|
want: "C--abcdefg",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := encodeCwdForDir(tc.cwd)
|
|
if got != tc.want {
|
|
t.Errorf("encodeCwdForDir(%q) = %q, want %q", tc.cwd, got, tc.want)
|
|
}
|
|
// Encoded directory must never contain characters that are
|
|
// illegal in Windows directory names.
|
|
for _, bad := range []string{":", "<", ">", "\"", "|", "?", "*", "\\", "/"} {
|
|
if strings.Contains(got, bad) {
|
|
t.Errorf("encodeCwdForDir(%q) = %q contains illegal char %q", tc.cwd, got, bad)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|