From d90894898f56ddb2a50290b922db71685e04d41d Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Tue, 9 Aug 2022 19:27:46 +0800 Subject: [PATCH] fix path format error --- internal/syncdrive/sync_db_util.go | 2 +- internal/syncdrive/sync_db_util_test.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/syncdrive/sync_db_util.go b/internal/syncdrive/sync_db_util.go index 05aa222..880cdae 100644 --- a/internal/syncdrive/sync_db_util.go +++ b/internal/syncdrive/sync_db_util.go @@ -13,7 +13,7 @@ func FormatFilePath(filePath string) string { } // 是否是windows路径 - matched, _ := regexp.MatchString("^[a-zA-Z]:*", filePath) + matched, _ := regexp.MatchString("^([a-zA-Z]:)", filePath) if matched { // 去掉卷标签,例如:D: filePath = string([]rune(filePath)[2:]) diff --git a/internal/syncdrive/sync_db_util_test.go b/internal/syncdrive/sync_db_util_test.go index f0946c1..a178f09 100644 --- a/internal/syncdrive/sync_db_util_test.go +++ b/internal/syncdrive/sync_db_util_test.go @@ -6,5 +6,9 @@ import ( ) func TestFormatFilePath(t *testing.T) { - fmt.Println(FormatFilePath("D:/-beyond/p/9168473.html")) + fmt.Println(FormatFilePath("D:\\-beyond\\p\\9168473.html")) +} + +func TestFormatFilePath2(t *testing.T) { + fmt.Println(FormatFilePath("/my/folder/test.txt")) }