Allow underscores at the start of directories in file backend.

Fixes #3476
This commit is contained in:
Jeff Mitchell 2017-10-19 12:13:43 -04:00
parent 03cd40345f
commit 3af3cf2b73
2 changed files with 48 additions and 3 deletions

View file

@ -247,10 +247,16 @@ func (b *FileBackend) ListInternal(prefix string) ([]string, error) {
}
for i, name := range names {
if name[0] == '_' {
names[i] = name[1:]
} else {
fi, err := os.Stat(filepath.Join(path, name))
if err != nil {
return nil, err
}
if fi.IsDir() {
names[i] = name + "/"
} else {
if name[0] == '_' {
names[i] = name[1:]
}
}
}

View file

@ -194,6 +194,45 @@ func ExerciseBackend(t *testing.T, b Backend) {
if len(keys) != 0 {
t.Fatalf("bad: %v", keys)
}
// Underscores should not trip things up; ref GH-3476
e = &Entry{Key: "_zip/_zap", Value: []byte("foobar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e, err = b.Get("_zip/_zap")
if err != nil {
t.Fatalf("err: %v", err)
}
if e == nil {
t.Fatal("got nil entry")
}
vals, err := b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zip/" {
t.Fatalf("bad: %v", vals)
}
vals, err = b.List("_zip/")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zap" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip/_zap")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 0 {
t.Fatalf("bad: %v", vals)
}
}
func ExerciseBackend_ListPrefix(t *testing.T, b Backend) {