aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/exclude_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/engine/exclude_test.go')
-rw-r--r--internal/engine/exclude_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go
index 4bb1512..4e9f6e7 100644
--- a/internal/engine/exclude_test.go
+++ b/internal/engine/exclude_test.go
@@ -302,3 +302,29 @@ func TestNoTextFormatIsNoMatch(t *testing.T) {
t.Errorf("explain: Excluded %q, want none", x.Excluded)
}
}
+
+// TestTextTurningBinaryFailsClosed: a file with no known extension whose
+// first 8 KiB read as text but which holds a NUL further on is unreadable,
+// not "no text": a content exclude still sets it aside (plan 10 re-check R4).
+func TestTextTurningBinaryFailsClosed(t *testing.T) {
+ mixed := "confidential " + strings.Repeat("x", 9000) + "\x00tail"
+ h, _ := excludeTree(t, map[string]string{"mixed": mixed})
+ main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": `
+(path "~/dl")
+(exclude (content "confidential"))
+(rule "all" (move "Out"))
+`})
+ 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 {
+ if fm.File.Rel == "mixed" && (!strings.HasSuffix(fm.Excluded, "(content unreadable)") || len(fm.Rules) != 0) {
+ t.Errorf("mixed: Excluded %q, rules %d; want set aside as unreadable", fm.Excluded, len(fm.Rules))
+ }
+ }
+}