From 902b5784659327a61ba7de56ef1885fcc6549b17 Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Fri, 20 Nov 2015 01:18:50 -0500
Subject: better escape char handle

---
 models/git_diff.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

(limited to 'models')

diff --git a/models/git_diff.go b/models/git_diff.go
index 4cc9ebf8fa..4b1ec09ea8 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -163,10 +163,10 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
 		if strings.HasPrefix(line, DIFF_HEAD) {
 			middle := -1
 
-			// Note: In case file name is surrounded by double quotes(it happens only in git-shell).
-			hasQuote := strings.Index(line, `\"`) > -1
+			// Note: In case file name is surrounded by double quotes (it happens only in git-shell).
+			// e.g. diff --git "a/xxx" "b/xxx"
+			hasQuote := line[len(DIFF_HEAD)] == '"'
 			if hasQuote {
-				line = strings.Replace(line, `\"`, `"`, -1)
 				middle = strings.Index(line, ` "b/`)
 			} else {
 				middle = strings.Index(line, " b/")
@@ -176,8 +176,8 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
 			a := line[beg+2 : middle]
 			b := line[middle+3:]
 			if hasQuote {
-				a = a[1 : len(a)-1]
-				b = b[1 : len(b)-1]
+				a = string(git.UnescapeChars([]byte(a[1 : len(a)-1])))
+				b = string(git.UnescapeChars([]byte(b[1 : len(b)-1])))
 			}
 
 			curFile = &DiffFile{
-- 
cgit v1.2.3