]> Sergey Matveev's repositories - btrtrc.git/commitdiff
fs: fix isSubPath for top-level directories (#105)
authorperses <costinc@gmail.com>
Mon, 1 Aug 2016 13:56:56 +0000 (16:56 +0300)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 1 Aug 2016 13:56:56 +0000 (23:56 +1000)
fs/torrentfs.go
fs/torrentfs_test.go

index 0f1cc9e6c7244b45b12ae02800e32cb4babf83b2..55834a241379e4a07d9aa3e8ca45590d6984e525 100644 (file)
@@ -158,6 +158,9 @@ var (
 )
 
 func isSubPath(parent, child string) bool {
+       if len(parent) == 0 {
+               return len(child) > 0
+       }
        if !strings.HasPrefix(child, parent) {
                return false
        }
index da83a75b391c2fd8ee88a509414e7c33ad365937..f3564124d724ada75df60b285b7143b0b757242d 100644 (file)
@@ -214,6 +214,7 @@ func TestIsSubPath(t *testing.T) {
        }{
                {"", "", false},
                {"", "/", true},
+               {"", "a", true},
                {"a/b", "a/bc", false},
                {"a/b", "a/b", false},
                {"a/b", "a/b/c", true},