mirror of
https://github.com/gogs/gogs.git
synced 2025-12-22 00:00:07 +01:00
wiki: fix crash with blob name contains tab (#3916)
This commit is contained in:
24
vendor/github.com/gogits/git-module/tree.go
generated
vendored
24
vendor/github.com/gogits/git-module/tree.go
generated
vendored
@@ -29,25 +29,23 @@ func NewTree(repo *Repository, id sha1) *Tree {
|
||||
}
|
||||
}
|
||||
|
||||
var escapeChar = []byte("\\")
|
||||
// Predefine []byte variables to avoid runtime allocations.
|
||||
var (
|
||||
escapedSlash = []byte(`\\`)
|
||||
regularSlash = []byte(`\`)
|
||||
escapedTab = []byte(`\t`)
|
||||
regularTab = []byte("\t")
|
||||
)
|
||||
|
||||
// UnescapeChars reverses escaped characters.
|
||||
func UnescapeChars(in []byte) []byte {
|
||||
if bytes.Index(in, escapeChar) == -1 {
|
||||
// LEGACY [Go 1.7]: use more expressive bytes.ContainsAny
|
||||
if bytes.IndexAny(in, "\\\t") == -1 {
|
||||
return in
|
||||
}
|
||||
|
||||
endIdx := len(in) - 1
|
||||
isEscape := false
|
||||
out := make([]byte, 0, endIdx+1)
|
||||
for i := range in {
|
||||
if in[i] == '\\' && !isEscape {
|
||||
isEscape = true
|
||||
continue
|
||||
}
|
||||
isEscape = false
|
||||
out = append(out, in[i])
|
||||
}
|
||||
out := bytes.Replace(in, escapedSlash, regularSlash, -1)
|
||||
out = bytes.Replace(out, escapedTab, regularTab, -1)
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user