summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2023-05-31 12:32:02 +0200
committerNicolas Paul <n@nc0.fr>2023-05-31 12:32:02 +0200
commite8b78cae016f7b3e05766b964b2618245fb0e021 (patch)
treeaa5d22e3d2f28d521946a1c0067907c31b88f478
parent4d22d9feeb6104c18e0f710fdeec8ea0cbea726b (diff)
Add a blacklist of module names to avoid problems with file generation
Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--pkg/config/starlark.go33
1 files changed, 31 insertions, 2 deletions
diff --git a/pkg/config/starlark.go b/pkg/config/starlark.go
index 986d39a..a954e92 100644
--- a/pkg/config/starlark.go
+++ b/pkg/config/starlark.go
@@ -9,8 +9,12 @@ import (
"go.nc0.fr/svgu/pkg/config/lib/svn"
"go.nc0.fr/svgu/pkg/types"
"go.starlark.net/starlark"
+ "strings"
)
+// https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
+const invalidName string = "..\\/<>:\"|?* \t\n\r\b\findex"
+
var registered types.Index
// ExecConfig configures the Starlark environment and executes the given
@@ -73,17 +77,42 @@ func InternIndex(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple,
}
// InternModule represents the built-in function "module".
-// module(name, vcs, repo, dir=None, file=None) registers a new module into the
+// module(name, vcs, repo, dir, file) registers a new module into the
// index.
func InternModule(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple,
kwargs []starlark.Tuple) (starlark.Value, error) {
var name, vcs, repo, dir, file string
if err := starlark.UnpackArgs("module", args, kwargs, "name",
- &name, "vcs", &vcs, "repo", &repo, "dir?", &dir, "file?", &file); err != nil {
+ &name, "vcs", &vcs, "repo", &repo, "dir", &dir, "file", &file); err != nil {
return nil, err
}
+ if registered.Domain == "" {
+ return nil, fmt.Errorf("index not initialized")
+ }
+
+ if name == "" {
+ return nil, fmt.Errorf("module name cannot be empty")
+ }
+
+ if vcs == "" {
+ return nil, fmt.Errorf("module %q vcs cannot be empty", name)
+ }
+
+ if repo == "" {
+ return nil, fmt.Errorf("module %q repo cannot be empty", name)
+ }
+
+ // Check for name conditions.
+ if strings.Contains(invalidName, name) {
+ return nil, fmt.Errorf("module %q name is invalid", name)
+ }
+
+ if registered.CheckModule(name) {
+ return nil, fmt.Errorf("module %q already exists", name)
+ }
+
var v types.Vcs
switch vcs {
case "git":