From 39cf5a7fde8fea752436ed21d038714ad9657da6 Mon Sep 17 00:00:00 2001 From: perses Date: Mon, 1 Aug 2016 16:56:56 +0300 Subject: [PATCH] fs: fix isSubPath for top-level directories (#105) --- fs/torrentfs.go | 3 +++ fs/torrentfs_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 0f1cc9e6..55834a24 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -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 } diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index da83a75b..f3564124 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -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}, -- 2.48.1