lib/ignore: Revert comma handling, upgrade globbing package
This was fixed upstream due to our ticket, so we no longer need the manual handling of commas. Keep the tests and better debug output around though. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3081
This commit is contained in:
committed by
Audrius Butkevicius
parent
d628b731d1
commit
1be40cc4fa
@@ -337,7 +337,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
continue
|
||||
}
|
||||
|
||||
line = escapeCommas(filepath.ToSlash(line))
|
||||
line = filepath.ToSlash(line)
|
||||
switch {
|
||||
case strings.HasPrefix(line, "#"):
|
||||
err = addPattern(line)
|
||||
@@ -358,49 +358,3 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
|
||||
return patterns, nil
|
||||
}
|
||||
|
||||
// escapes unescaped commas encountered outside of brackets
|
||||
func escapeCommas(s string) string {
|
||||
buf := make([]rune, 0, len(s))
|
||||
inEscape := false
|
||||
inBrackets := 0
|
||||
inSquareBrackets := 0
|
||||
for _, r := range s {
|
||||
// Escaped characters are passed on verbatim no matter what, and we
|
||||
// clear the escape flag for the next character.
|
||||
if inEscape {
|
||||
buf = append(buf, r)
|
||||
inEscape = false
|
||||
continue
|
||||
}
|
||||
|
||||
// Check for escapes and commas to escape. Also keep track of the
|
||||
// brackets level by counting start and end brackets of the two
|
||||
// types.
|
||||
|
||||
switch r {
|
||||
case '\\':
|
||||
inEscape = true
|
||||
|
||||
case '{':
|
||||
inBrackets++
|
||||
case '}':
|
||||
inBrackets--
|
||||
case '[':
|
||||
inSquareBrackets++
|
||||
case ']':
|
||||
inSquareBrackets--
|
||||
|
||||
case ',':
|
||||
// Commas should be escaped if we're not inside a brackets
|
||||
// construction, and if they weren't already escaped (in which
|
||||
// case we'll have taken the first branch way up top).
|
||||
if inBrackets == 0 && inSquareBrackets == 0 {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
}
|
||||
|
||||
buf = append(buf, r)
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user