summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-20 01:18:50 -0500
committerUnknwon <u@gogs.io>2015-11-20 01:18:50 -0500
commit902b5784659327a61ba7de56ef1885fcc6549b17 (patch)
tree8ddbe345e2140d300a20b74c47bd654ff728b096 /modules
parent3d14e73fd835f2a0ed4a22daa4c67df245be8103 (diff)
downloadgitea-902b5784659327a61ba7de56ef1885fcc6549b17.tar.gz
gitea-902b5784659327a61ba7de56ef1885fcc6549b17.zip
better escape char handle
Diffstat (limited to 'modules')
-rw-r--r--modules/git/tree.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/modules/git/tree.go b/modules/git/tree.go
index 6cfdbf47c2..1a561cf5c1 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -30,7 +30,7 @@ type Tree struct {
var escapeChar = []byte("\\")
-func unescapeChars(in []byte) []byte {
+func UnescapeChars(in []byte) []byte {
if bytes.Index(in, escapeChar) == -1 {
return in
}
@@ -39,12 +39,11 @@ func unescapeChars(in []byte) []byte {
isEscape := false
out := make([]byte, 0, endIdx+1)
for i := range in {
- if in[i] == '\\' && i != endIdx {
- isEscape = !isEscape
- if isEscape {
- continue
- }
+ if in[i] == '\\' && !isEscape {
+ isEscape = true
+ continue
}
+ isEscape = false
out = append(out, in[i])
}
return out
@@ -92,11 +91,12 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
pos += step + 1 // Skip half of sha1.
step = bytes.IndexByte(data[pos:], '\n')
- entry.name = string(data[pos : pos+step])
// In case entry name is surrounded by double quotes(it happens only in git-shell).
- if entry.name[0] == '"' {
- entry.name = string(unescapeChars(data[pos+1 : pos+step-1]))
+ if data[pos] == '"' {
+ entry.name = string(UnescapeChars(data[pos+1 : pos+step-1]))
+ } else {
+ entry.name = string(data[pos : pos+step])
}
pos += step + 1