From 11b35d650d279000b2207549100001e089e637c6 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Fri, 16 Dec 2016 11:21:22 +0000 Subject: [PATCH] lib/model: Accept scan requests of paths ending in slash (fixes #3804) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3805 --- lib/model/model.go | 5 ++++- lib/model/model_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/model/model.go b/lib/model/model.go index 66161d3cb..2d536824f 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -1690,7 +1690,10 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error for i, sub := range subDirs { sub = osutil.NativeFilename(sub) // We test each path by joining with "root". What we join with is - // not relevant, we just want the dotdot escape detection here. + // not relevant, we just want the dotdot escape detection here. For + // historical reasons we may get paths that end in a slash. We + // remove that first to allow the rootedJoinedPath to pass. + sub = strings.TrimRight(sub, string(os.PathSeparator)) if _, err := rootedJoinedPath("root", sub); err != nil { return errors.New("invalid subpath") } diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 17e245c84..27fdaffd7 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -2166,6 +2166,21 @@ func TestIssue3496(t *testing.T) { } } +func TestIssue3804(t *testing.T) { + dbi := db.OpenMemory() + m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", dbi, nil) + m.AddFolder(defaultFolderConfig) + m.StartFolder("default") + m.ServeBackground() + defer m.Stop() + + // Subdirs ending in slash should be accepted + + if err := m.ScanFolderSubdirs("default", []string{"baz/", "foo"}); err != nil { + t.Error("Unexpected error:", err) + } +} + func TestRootedJoinedPath(t *testing.T) { type testcase struct { root string