We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99bc113 commit 87e6dacCopy full SHA for 87e6dac
1 file changed
utils/replace_path_prefix.go
@@ -1,12 +1,25 @@
1
package utils
2
3
-import "strings"
+import (
4
+ "strings"
5
+)
6
7
func ReplacePathPrefix(fullPath string, realPrefix string) string {
8
fullPath = strings.ReplaceAll(fullPath, "\\", "/")
9
+ realPrefix = strings.ReplaceAll(realPrefix, "\\", "/")
10
11
if strings.HasPrefix(fullPath, realPrefix) {
- 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:]
23
}
24
25
return fullPath
0 commit comments