From 8c6afca96a9f0af41c5a9d05beb7f1dedb994740 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 21:24:22 +0200 Subject: plan 9: placeholders stay inside the directory the rule names --- internal/plan/fuzz_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'internal/plan/fuzz_test.go') diff --git a/internal/plan/fuzz_test.go b/internal/plan/fuzz_test.go index fb68f94..6deb225 100644 --- a/internal/plan/fuzz_test.go +++ b/internal/plan/fuzz_test.go @@ -3,13 +3,21 @@ package plan import ( + "path/filepath" + "strings" "testing" "time" + + "krino/internal/config" + "krino/internal/scan" ) // FuzzExpand: expanding any template against any file name never panics, // gives the same answer twice, and never succeeds with a {N} beyond the // capture groups there are - MaxIndex and Expand read placeholders alike. +// Used as a destination - relative, in the home directory, or bare - a +// template never plans a move outside the directory its text names before +// the first placeholder (review M1). func FuzzExpand(f *testing.F) { for _, s := range []string{"{name}", "{stem}{ext}", "{mtime:%Y/%m}", "{1}_{2}", "{{literal}}", "{", "}", "{now:%", "{0}", "{9}", "{99999999999999999999}"} { f.Add(s, "a.b.pdf") @@ -29,5 +37,15 @@ func FuzzExpand(f *testing.F) { if n, err := MaxIndex(tmpl); err == nil && n > 2 && errA == nil { t.Fatalf("Expand(%q) = %q, though it uses {%d} and only 2 groups exist", tmpl, a, n) } + for _, dest := range []string{tmpl, "Out/" + tmpl, "~/docs/" + tmpl} { + in := []Input{{ + File: scan.File{Path: "/r/x.pdf", Rel: "x.pdf", Name: "x.pdf", ModTime: facts.ModTime}, + Rules: []RuleMatch{{Name: "a", Captures: facts.Captures, Actions: []config.Action{{Kind: config.Move, Arg: dest}}}}, + }} + s := Build("/r", in, facts.Now, NoDisk{}, NewClaims())[0].Steps[0] + if strings.ContainsRune(dest, '{') && s.Skip == "" && !within(filepath.Dir(s.Dst), staticDir(dest, "/r")) { + t.Fatalf("destination %q planned %q, outside %q", dest, s.Dst, staticDir(dest, "/r")) + } + } }) } -- cgit v1.3