Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde66ba4

Browse files
authored
fix: panic inregexp.MustCompile when building wildcarddirectories with non ascii characters (#1947)
1 parent6126dab commitde66ba4

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
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-
varexcludeRegex*regexp.Regexp
30+
varexcludeRegex*regexp2.Regexp
3231
ifrawExcludeRegex!="" {
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:=rangeinclude {
4645
spec:=tspath.NormalizeSlashes(tspath.CombinePaths(comparePathsOptions.CurrentDirectory,file))
47-
ifexcludeRegex!=nil&&excludeRegex.MatchString(spec) {
48-
continue
46+
ifexcludeRegex!=nil {
47+
ifmatched,_:=excludeRegex.MatchString(spec);matched {
48+
continue
49+
}
4950
}
5051

5152
match:=getWildcardDirectoryFromSpec(spec,comparePathsOptions.UseCaseSensitiveFileNames)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package tsoptions
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/tspath"
7+
)
8+
9+
funcTestGetWildcardDirectories_NonASCIICharacters(t*testing.T) {
10+
t.Parallel()
11+
12+
tests:= []struct {
13+
namestring
14+
include []string
15+
exclude []string
16+
currentDirectorystring
17+
useCaseSensitiveFileNamesbool
18+
}{
19+
{
20+
name:"Norwegian character æ in path",
21+
include: []string{"src/**/*.test.ts","src/**/*.stories.ts","src/**/*.mdx"},
22+
exclude: []string{"node_modules"},
23+
currentDirectory:"C:/Users/TobiasLægreid/dev/app/frontend/packages/react",
24+
useCaseSensitiveFileNames:false,
25+
},
26+
{
27+
name:"Japanese characters in path",
28+
include: []string{"src/**/*.ts"},
29+
exclude: []string{"テスト"},
30+
currentDirectory:"/Users/ユーザー/プロジェクト",
31+
useCaseSensitiveFileNames:true,
32+
},
33+
{
34+
name:"Chinese characters in path",
35+
include: []string{"源代码/**/*.js"},
36+
exclude: []string{"节点模块"},
37+
currentDirectory:"/home/用户/项目",
38+
useCaseSensitiveFileNames:true,
39+
},
40+
{
41+
name:"Various Unicode characters",
42+
include: []string{"src/**/*.ts"},
43+
exclude: []string{"node_modules"},
44+
currentDirectory:"/Users/Müller/café/naïve/résumé",
45+
useCaseSensitiveFileNames:false,
46+
},
47+
}
48+
49+
for_,tt:=rangetests {
50+
t.Run(tt.name,func(t*testing.T) {
51+
t.Parallel()
52+
53+
comparePathsOptions:= tspath.ComparePathsOptions{
54+
CurrentDirectory:tt.currentDirectory,
55+
UseCaseSensitiveFileNames:tt.useCaseSensitiveFileNames,
56+
}
57+
58+
result:=getWildcardDirectories(tt.include,tt.exclude,comparePathsOptions)
59+
60+
ifresult==nil {
61+
t.Fatalf("expected non-nil result")
62+
}
63+
})
64+
}
65+
}

‎internal/vfs/utilities.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ func IsImplicitGlob(lastPathComponent string) bool {
8181
return!strings.ContainsAny(lastPathComponent,".*?")
8282
}
8383

84-
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
85-
//It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
86-
//proof.
84+
// Reserved characters - only escape actual regex metacharacters.
85+
//Go's regexp doesn't support \x escape sequences for arbitrary characters,
86+
//so we only escape characters that have special meaning in regex.
8787
var (
88-
reservedCharacterPattern*regexp.Regexp=regexp.MustCompile(`[^\w\s/]`)
88+
reservedCharacterPattern*regexp.Regexp=regexp.MustCompile(`[\\.\+*?()\[\]{}^$|#]`)
8989
wildcardCharCodes= []rune{'*','?'}
9090
)
9191

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp