Skip to content

Commit 87e6dac

Browse files
committed
fix: ReplacePathPrefix function
1 parent 99bc113 commit 87e6dac

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

utils/replace_path_prefix.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package utils
22

3-
import "strings"
3+
import (
4+
"strings"
5+
)
46

57
func ReplacePathPrefix(fullPath string, realPrefix string) string {
68
fullPath = strings.ReplaceAll(fullPath, "\\", "/")
9+
realPrefix = strings.ReplaceAll(realPrefix, "\\", "/")
710

811
if strings.HasPrefix(fullPath, realPrefix) {
9-
return "./" + fullPath[len(realPrefix):]
12+
realPrefixLen := len(realPrefix)
13+
14+
if realPrefixLen >= len(fullPath) {
15+
return "./"
16+
}
17+
18+
if string(fullPath[realPrefixLen]) == "/" {
19+
return "." + fullPath[realPrefixLen:]
20+
}
21+
22+
return "./" + fullPath[realPrefixLen:]
1023
}
1124

1225
return fullPath

0 commit comments

Comments
 (0)