diff --git a/CHANGELOG.md b/CHANGELOG.md index fe20fe5..00755cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ and versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [0.5.1] - 2026-10-16 + +### Fixed +- Project names that Windows cannot create (`CON`, `NUL`, `COM1`, `LPT1`, a trailing dot) are refused with a clear message on every platform, so a project made on Linux can be checked out on Windows. + ## [0.5.0] - 2026-10-16 ### Added diff --git a/internal/project/project.go b/internal/project/project.go index 4779c4d..bd725bd 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -92,10 +92,31 @@ func ValidateName(name string) error { return errors.New(`project name cannot contain any of : * ? " < > |`) case len(name) > 100: return errors.New("project name is longer than 100 characters") + case strings.HasSuffix(name, "."): + return errors.New("project name cannot end with a dot (Windows cannot create such a folder)") + case isWindowsReserved(name): + return fmt.Errorf("%q is a reserved device name on Windows; choose another project name", name) } return nil } +// isWindowsReserved reports whether name (ignoring any extension) is a Windows device name such as CON or COM1. +// Projects are meant to be portable, so the name is refused on every platform. +func isWindowsReserved(name string) bool { + base := strings.ToUpper(name) + if i := strings.Index(base, "."); i >= 0 { + base = base[:i] + } + switch base { + case "CON", "PRN", "AUX", "NUL": + return true + } + if len(base) == 4 && (strings.HasPrefix(base, "COM") || strings.HasPrefix(base, "LPT")) { + return base[3] >= '1' && base[3] <= '9' + } + return false +} + // BuildPlan walks the template and decides what a project would contain. It writes nothing. func BuildPlan(opts Options) (*Plan, error) { if opts.Now.IsZero() { diff --git a/internal/project/project_test.go b/internal/project/project_test.go index 6d5e9b9..6879e29 100644 --- a/internal/project/project_test.go +++ b/internal/project/project_test.go @@ -222,12 +222,12 @@ func TestExecutableBitIsPreserved(t *testing.T) { } func TestValidateName(t *testing.T) { - for _, ok := range []string{"app", "my-app", "My App", "a.b_c"} { + for _, ok := range []string{"app", "my-app", "My App", "a.b_c", "console", "com", "com10", "COM0"} { if err := ValidateName(ok); err != nil { t.Errorf("%q: %v", ok, err) } } - for _, bad := range []string{"", " ", ".", "..", "a/b", `a\b`, "a:b", "a*b", " x", strings.Repeat("x", 101)} { + for _, bad := range []string{"", " ", ".", "..", "a/b", `a\b`, "a:b", "a*b", " x", strings.Repeat("x", 101), "CON", "nul", "Com1", "lpt9.txt", "app."} { if err := ValidateName(bad); err == nil { t.Errorf("%q should be invalid", bad) }