From 394d117b90ffb64c87adfc8c2436b57007840c2b Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 22:23:42 +0200 Subject: plan 10: a format with no text is no match, not unreadable --- internal/engine/exclude_test.go | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'internal/engine/exclude_test.go') diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go index 87fa16c..4bb1512 100644 --- a/internal/engine/exclude_test.go +++ b/internal/engine/exclude_test.go @@ -260,3 +260,45 @@ func TestLoadChecksMainExcludesWithoutDirectories(t *testing.T) { t.Error("a broken krino.conf exclude was not reported") } } + +// TestNoTextFormatIsNoMatch: a file whose format has no text cannot contain +// a keyword, so a content exclude without a type does not set it aside, and +// no "content unreadable" warning is raised - while a real read failure (over +// max-read) still fails closed (re-review N2, Ɓukasz's decision). +func TestNoTextFormatIsNoMatch(t *testing.T) { + big := "confidential " + strings.Repeat("x", 2048) + h, dl := excludeTree(t, map[string]string{"photo.jpg": "\xff\xd8\xff\x00\x01binary", "big.txt": big}) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": ` +(path "~/dl") +(max-read 1K) +(exclude (content "confidential")) +(rule "pics" (when (type jpg)) (move "Pictures")) +`}) + e, errs := Load(main) + if len(errs) > 0 { + t.Fatal(errs) + } + r, err := e.Match(context.Background(), e.Dirs[0]) + if err != nil { + t.Fatal(err) + } + for _, fm := range r.Matched { + switch fm.File.Rel { + case "photo.jpg": + if fm.Excluded != "" || len(fm.Rules) != 1 || len(fm.Warnings) != 0 { + t.Errorf("photo.jpg: Excluded %q, rules %d, warnings %v; want the pics rule and no warning", fm.Excluded, len(fm.Rules), fm.Warnings) + } + case "big.txt": + if !strings.HasSuffix(fm.Excluded, "(content unreadable)") { + t.Errorf("big.txt: Excluded %q; a real read failure must still fail closed", fm.Excluded) + } + } + } + x, err := e.Explain(context.Background(), filepath.Join(dl, "photo.jpg")) + if err != nil { + t.Fatal(err) + } + if x.Excluded != "" { + t.Errorf("explain: Excluded %q, want none", x.Excluded) + } +} -- cgit v1.3