summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-20 00:47:35 -0500
committerUnknwon <u@gogs.io>2015-11-20 00:47:35 -0500
commit3d14e73fd835f2a0ed4a22daa4c67df245be8103 (patch)
tree725e4331dd5fa5960944bfc084c06b4c63263fc7 /modules
parent9bcc3c1ea3f3d2e7a68e7da7d6267e0f30bc3027 (diff)
downloadgitea-3d14e73fd835f2a0ed4a22daa4c67df245be8103.tar.gz
gitea-3d14e73fd835f2a0ed4a22daa4c67df245be8103.zip
fix #1119 and data race in timming tasks
Diffstat (limited to 'modules')
-rw-r--r--modules/git/tree.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/modules/git/tree.go b/modules/git/tree.go
index cc62a2d528..6cfdbf47c2 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -28,6 +28,28 @@ type Tree struct {
entriesParsed bool
}
+var escapeChar = []byte("\\")
+
+func unescapeChars(in []byte) []byte {
+ if bytes.Index(in, escapeChar) == -1 {
+ return in
+ }
+
+ endIdx := len(in) - 1
+ isEscape := false
+ out := make([]byte, 0, endIdx+1)
+ for i := range in {
+ if in[i] == '\\' && i != endIdx {
+ isEscape = !isEscape
+ if isEscape {
+ continue
+ }
+ }
+ out = append(out, in[i])
+ }
+ return out
+}
+
// Parse tree information from the (uncompressed) raw
// data from the tree object.
func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
@@ -74,8 +96,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
// In case entry name is surrounded by double quotes(it happens only in git-shell).
if entry.name[0] == '"' {
- entry.name = string(data[pos+1 : pos+step-1])
- entry.name = strings.Replace(entry.name, `\"`, `"`, -1)
+ entry.name = string(unescapeChars(data[pos+1 : pos+step-1]))
}
pos += step + 1