You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When checking if an Addition belongs to any scopes, we should compare
just the basename of the Addition instead of using the standard
filename/path matching logic.
Authored-by: Owen Nelson <[email protected]>
// Matches states whether the addition matches the given pattern.
191
-
// If the pattern ends in a path separator, then all files inside a directory with that name are matched. However, files with that name itself will not be matched.
192
-
// If a pattern contains the path separator in any other location, the match works according to the pattern logic of the default golang glob mechanism
193
-
// If there are other special characters in the pattern, the pattern is matched against the base name of the file. Thus, the pattern will match files with that pattern anywhere in the repository.
194
-
// If there are no special characters in the pattern, then it means exact filename is provided as pattern like file.txt. Thus, the pattern is matched against the file path so that not all files with the same name in the repo are not returned.
190
+
// Matches reports whether the addition matches the given pattern.
191
+
//
192
+
// If the pattern ends in a path separator, then all files inside a directory with that name are matched.
193
+
// However, files with that name itself will not be matched.
194
+
//
195
+
// If a pattern contains the path separator in any other location,
196
+
// the match works according to the pattern logic of the default golang glob mechanism.
197
+
//
198
+
// If there are other special characters in the pattern, the pattern is matched against the base name of the file.
199
+
// Thus, the pattern will match files with that pattern anywhere in the repository.
200
+
//
201
+
// If there are no special characters in the pattern, then it means exact filename is provided as pattern like file.txt.
202
+
// Thus, the pattern is matched against the file path so that not all files with the same name in the repo are not returned.
195
203
func (aAddition) Matches(patternstring) bool {
196
204
varresultbool
197
205
ifpattern[len(pattern)-1] =='/' { // If the pattern ends in a path separator, then all files inside a directory with that name are matched. However, files with that name itself will not be matched.
198
206
result=strings.HasPrefix(string(a.Path), pattern)
199
207
} elseifstrings.ContainsRune(pattern, '/') { // If a pattern contains the path separator in any other location, the match works according to the pattern logic of the default golang glob mechanism
200
208
result, _=path.Match(pattern, string(a.Path))
201
209
} elseifstrings.ContainsAny(pattern, "*?[]\\") { // If there are other special characters in the pattern, the pattern is matched against the base name of the file. Thus, the pattern will match files with that pattern anywhere in the repository.
202
-
result, _=path.Match(pattern, string(a.Name))
210
+
result=a.NameMatches(pattern)
203
211
} else { // If there are no special characters in the pattern, then it means exact filename is provided as pattern like file.txt. Thus, the pattern is matched against the file path so that not all files with the same name in the repo are not returned.
0 commit comments