Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply package name constraints to env vars, dirs
Applies the constraints articulated in compose-spec/compose-spec#314 for project names from `COMPOSE_PROJECT_NAME`, the project dir, or the working dir. Before this change, the constraints applied only when using `docker compose -p` or the `name:` config file property. Non-normalized project names from `COMPOSE_PROJECT_NAME`, the project dir, or the working dir were still allowed, which `docker compose` would then normalize. The constraints are enforced by: - `cli.ProjectFromOptions()` setting `withNamePrecedenceLoad()` as an option to `loader.Load()`. - `loader.Load()` applies `withNamePrecedenceLoad()`, which tries to get the project name from the command line options, then `COMPOSE_PROJECT_NAME`, then the project or working dir. - `withNamePrecedenceLoad()` calls `loader.Options.SetProjectName()`, which now also saves the original name as well as the normalized name. - `loader.Load()` then calls `loader.projectName()`, which reads the project name from the config file(s) if it's not already set. - `loader.projectName()` then applies the new `CheckOriginalProjectNameIsNormalized()` function extracted from `cli.WithName()`. Only a handful of test cases required updating in `cli/options_test.go`. These test cases were checking that invalid project names were rejected by `cli.WithName()`, but that `cli.ProjectFromOptions()` would normalize them. Now `cli.ProjectFromOptions()` rejects them with the same error. There's no need for new test cases specifically for `COMPOSE_PROJECT_NAME` or directory-based project names, because the `CheckOriginalProjectNameIsNormalized()` function is applied regardless of the source. Other existing test cases are validating that `cli.ProjectFromOptions` does also use `COMPOSE_PROJECT_NAME` or directory names when necessary. Closes compose-spec#363. Signed-off-by: Mike Bland <[email protected]>
- Loading branch information