瀏覽代碼

lib/model: Invalidate files with trailing white space on Windows (fixes #3227)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3383
Jakob Borg 9 年之前
父節點
當前提交
aa50ef4069
共有 2 個文件被更改,包括 28 次插入1 次删除
  1. 1 1
      lib/protocol/nativemodel_windows.go
  2. 27 0
      lib/protocol/nativemodel_windows_test.go

+ 1 - 1
lib/protocol/nativemodel_windows.go

@@ -41,7 +41,7 @@ func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offs
 
 func fixupFiles(folder string, files []FileInfo) {
 	for i, f := range files {
-		if strings.ContainsAny(f.Name, disallowedCharacters) {
+		if strings.ContainsAny(f.Name, disallowedCharacters) || strings.HasSuffix(f.Name, " ") {
 			if f.IsDeleted() {
 				// Don't complain if the file is marked as deleted, since it
 				// can't possibly exist here anyway.

+ 27 - 0
lib/protocol/nativemodel_windows_test.go

@@ -0,0 +1,27 @@
+// Copyright (C) 2016 The Protocol Authors.
+
+// +build windows
+
+package protocol
+
+import "testing"
+
+func TestFixupFiles(t *testing.T) {
+	fs := []FileInfo{
+		{Name: "ok"},  // This file is OK
+		{Name: "b<d"}, // The rest should be marked as invalid
+		{Name: "b?d"},
+		{Name: "bad "},
+	}
+
+	fixupFiles("default", fs)
+
+	if fs[0].IsInvalid() {
+		t.Error("fs[0] should not be invalid")
+	}
+	for i := 1; i < len(fs); i++ {
+		if !fs[i].IsInvalid() {
+			t.Errorf("fs[%d] should be invalid", i)
+		}
+	}
+}