@@ -3,6 +3,8 @@ package util
33import (
44 "fmt"
55 "math"
6+ "os"
7+ "path/filepath"
68 "runtime"
79 "sort"
810 "testing"
@@ -864,3 +866,31 @@ func TestGetRootlessStateDir(t *testing.T) {
864866 assert .NoError (t , err )
865867 assert .NotEqual (t , dir , "libpod/tmp" )
866868}
869+
870+ // https://github.com/containers/podman/issues/25458
871+ func TestParseDockerignoreLeadingTrailingSlashes (t * testing.T ) {
872+ contextDir := t .TempDir ()
873+
874+ for _ , tt := range []struct {
875+ name string
876+ ignore string
877+ expected []string
878+ }{
879+ {"leading slash" , "/.git/\n " , []string {".git" }},
880+ {"trailing slash" , "target/\n " , []string {"target" }},
881+ {"both slashes" , "/build/\n " , []string {"build" }},
882+ {"no slashes" , "vendor\n " , []string {"vendor" }},
883+ {"slash only line" , "/\n " , []string {}},
884+ {"multiple patterns" , "/.git/\n /target/\n vendor\n " , []string {".git" , "target" , "vendor" }},
885+ } {
886+ t .Run (tt .name , func (t * testing.T ) {
887+ ignorePath := filepath .Join (contextDir , ".containerignore" )
888+ err := os .WriteFile (ignorePath , []byte (tt .ignore ), 0o644 )
889+ assert .NoError (t , err )
890+
891+ excludes , _ , err := ParseDockerignore (nil , contextDir )
892+ assert .NoError (t , err )
893+ assert .Equal (t , tt .expected , excludes )
894+ })
895+ }
896+ }
0 commit comments