From a6971d77a63bc9a9564d6b8d67c7b9ee67fa7fbb Mon Sep 17 00:00:00 2001 From: Seidko Date: Thu, 22 Feb 2024 12:51:22 +0800 Subject: [PATCH 1/2] fix: YarnPnP resolve drive letter correctly --- internal/fs/fs_zip.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/fs/fs_zip.go b/internal/fs/fs_zip.go index 4f168f25fad..3759888a816 100644 --- a/internal/fs/fs_zip.go +++ b/internal/fs/fs_zip.go @@ -24,6 +24,7 @@ import ( "strings" "sync" "syscall" + "unicode" ) type zipFS struct { @@ -330,6 +331,10 @@ func (fs *zipFS) WatchData() WatchData { return fs.inner.WatchData() } +func HasDriveLetter(path string) bool { + return unicode.IsLetter(rune(path[0])) && path[1] == ':' +} + func ParseYarnPnPVirtualPath(path string) (string, string, bool) { i := 0 @@ -356,7 +361,7 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) { // Find the range of the count if slash := strings.IndexAny(path[j:], "/\\"); slash != -1 { count = path[j : j+slash] - suffix = path[j+slash:] + suffix = path[j+slash+1:] } else { count = path[j:] } @@ -369,6 +374,9 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) { for n > 0 && (strings.HasSuffix(prefix, "/") || strings.HasSuffix(prefix, "\\")) { slash := strings.LastIndexAny(prefix[:len(prefix)-1], "/\\") if slash == -1 { + if HasDriveLetter(prefix) { + prefix = "" + } break } prefix = prefix[:slash+1] @@ -378,8 +386,8 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) { // Make sure the prefix and suffix work well when joined together if suffix == "" && strings.IndexAny(prefix, "/\\") != strings.LastIndexAny(prefix, "/\\") { prefix = prefix[:len(prefix)-1] - } else if prefix == "" { - prefix = "." + } else if prefix == "" && !HasDriveLetter(suffix) { + prefix = "./" } else if strings.HasPrefix(suffix, "/") || strings.HasPrefix(suffix, "\\") { suffix = suffix[1:] } From f033c6d6034565d324cb1b6d792a7bc7e5d38dcd Mon Sep 17 00:00:00 2001 From: Seidko Date: Thu, 22 Feb 2024 13:58:31 +0800 Subject: [PATCH 2/2] fix: check path length --- internal/fs/fs_zip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/fs/fs_zip.go b/internal/fs/fs_zip.go index 3759888a816..13c0381a000 100644 --- a/internal/fs/fs_zip.go +++ b/internal/fs/fs_zip.go @@ -332,7 +332,7 @@ func (fs *zipFS) WatchData() WatchData { } func HasDriveLetter(path string) bool { - return unicode.IsLetter(rune(path[0])) && path[1] == ':' + return len(path) >= 2 && unicode.IsLetter(rune(path[0])) && path[1] == ':' } func ParseYarnPnPVirtualPath(path string) (string, string, bool) {