Skip to content

Commit 831cc2b

Browse files
fix(path): ensure case insensitive matching on Windows
resolves #6329
1 parent 754a1d2 commit 831cc2b

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/segments/path.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,33 @@ func (pt *Path) replaceMappedLocations(inputPath string) (string, string) {
617617
return strings.NewReplacer("<", "<<>", ">", "<>>").Replace(path)
618618
}
619619

620-
for _, key := range keys {
621-
if strings.HasPrefix(key, regexPrefix) {
622-
input := strings.ReplaceAll(inputPath, `\`, `/`)
623-
match, OK := regex.FindStringMatch(key[len(regexPrefix):], input, 1)
624-
if !OK {
625-
continue
626-
}
620+
handleRegex := func(key string) (string, bool) {
621+
if !strings.HasPrefix(key, regexPrefix) {
622+
return "", false
623+
}
624+
625+
input := strings.ReplaceAll(inputPath, `\`, `/`)
626+
pattern := key[len(regexPrefix):]
627+
628+
// Add (?i) at the start of the pattern for case-insensitive matching on Windows
629+
if pt.windowsPath || (pt.env.IsWsl() && strings.HasPrefix(input, "/mnt/")) {
630+
pattern = "(?i)" + pattern
631+
}
627632

628-
// Replace the first match with the mapped location.
629-
input = strings.Replace(input, match, pt.mappedLocations[key], 1)
630-
input = path.Clean(input)
633+
match, OK := regex.FindStringMatch(pattern, input, 1)
634+
if !OK {
635+
return "", false
636+
}
637+
638+
// Replace the first match with the mapped location.
639+
input = strings.Replace(input, match, pt.mappedLocations[key], 1)
640+
input = path.Clean(input)
641+
642+
return input, true
643+
}
644+
645+
for _, key := range keys {
646+
if input, OK := handleRegex(key); OK {
631647
return pt.parsePath(input)
632648
}
633649

src/segments/path_windows_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ var testFullPathCustomMappedLocationsCases = []testFullPathCustomMappedLocations
442442
Expected: `\a\b\1234\f\e`,
443443
},
444444
{
445-
Pwd: `C:\Users\taylo\Documents\GitHub\project`,
445+
Pwd: `C:\Users\taylo\Documents\github\project`,
446446
MappedLocations: map[string]string{`re:(.*Users/taylo/Documents/GitHub).*`: "github"},
447447
GOOS: runtime.WINDOWS,
448448
PathSeparator: `\`,

0 commit comments

Comments
 (0)