From d350b1ad60e459f5f23dac048ae0656e9d738975 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Tue, 30 Jan 2024 04:02:54 +0800 Subject: [PATCH] fix: protect path --- package_test.go | 2 +- utils.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package_test.go b/package_test.go index 0c85783..744ccd0 100644 --- a/package_test.go +++ b/package_test.go @@ -461,7 +461,7 @@ func TestCommandLineArgumentsPagkageDetection(t *testing.T) { }{ {"x_cgo_sys_thread_creater", ".", ClassSTD}, {"_cgo_sys_thread_star", ".", ClassSTD}, - {"", ".", ClassGenerated}, + {"", "", ClassGenerated}, {"gopackage", "gopackage", ClassMain}, {"gopackage/subpackage", "gopackage/subpackage", ClassMain}, } diff --git a/utils.go b/utils.go index a86ed38..fa0d6d6 100644 --- a/utils.go +++ b/utils.go @@ -5,16 +5,26 @@ package gore import ( "path/filepath" + "strings" ) func osAwarePathDir(s string) string { - return filepath.Dir(s) + if strings.Contains(s, "/") { + return filepath.Dir(s) + } + return s } func osAwarePathBase(s string) string { - return filepath.Base(s) + if strings.Contains(s, "/") { + return filepath.Base(s) + } + return s } func osAwarePathClean(s string) string { - return filepath.Clean(s) + if strings.Contains(s, "/") { + return filepath.Clean(s) + } + return s }