Skip to content

Commit 136d7fe

Browse files
committed
fix: use regexp2 instead of regexp in getWildcardDirectories
Switch from Go's standard regexp package to regexp2 with ECMAScript mode to properly handle Unicode characters in file paths. The standard regexp package doesn't support ECMAScript regex semantics, which the original code was trying to emulate.
1 parent 6bf5543 commit 136d7fe

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

internal/tsoptions/wildcarddirectories.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tsoptions
22

33
import (
4-
"regexp"
54
"strings"
65

76
"github.com/dlclark/regexp2"
@@ -28,13 +27,13 @@ func getWildcardDirectories(include []string, exclude []string, comparePathsOpti
2827
}
2928

3029
rawExcludeRegex := vfs.GetRegularExpressionForWildcard(exclude, comparePathsOptions.CurrentDirectory, "exclude")
31-
var excludeRegex *regexp.Regexp
30+
var excludeRegex *regexp2.Regexp
3231
if rawExcludeRegex != "" {
33-
options := ""
32+
flags := regexp2.ECMAScript
3433
if !comparePathsOptions.UseCaseSensitiveFileNames {
35-
options = "(?i)"
34+
flags |= regexp2.IgnoreCase
3635
}
37-
excludeRegex = regexp.MustCompile(options + rawExcludeRegex)
36+
excludeRegex = regexp2.MustCompile(rawExcludeRegex, regexp2.RegexOptions(flags))
3837
}
3938

4039
wildcardDirectories := make(map[string]bool)
@@ -44,8 +43,10 @@ func getWildcardDirectories(include []string, exclude []string, comparePathsOpti
4443

4544
for _, file := range include {
4645
spec := tspath.NormalizeSlashes(tspath.CombinePaths(comparePathsOptions.CurrentDirectory, file))
47-
if excludeRegex != nil && excludeRegex.MatchString(spec) {
48-
continue
46+
if excludeRegex != nil {
47+
if matched, _ := excludeRegex.MatchString(spec); matched {
48+
continue
49+
}
4950
}
5051

5152
match := getWildcardDirectoryFromSpec(spec, comparePathsOptions.UseCaseSensitiveFileNames)

0 commit comments

Comments
 (0)