better escape char handle
This commit is contained in:
parent
3d14e73fd8
commit
902b578465
@ -13,7 +13,6 @@ watch_dirs = [
|
|||||||
watch_exts = [".go"]
|
watch_exts = [".go"]
|
||||||
build_delay = 1500
|
build_delay = 1500
|
||||||
cmds = [
|
cmds = [
|
||||||
["go", "install"],
|
|
||||||
["go", "install", "-race"], # sqlite redis memcache cert pam tidb
|
["go", "install", "-race"], # sqlite redis memcache cert pam tidb
|
||||||
["go", "build", "-race"],
|
["go", "build", "-race"],
|
||||||
["./gogs", "web"]
|
["./gogs", "web"]
|
||||||
|
@ -163,10 +163,10 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
|
|||||||
if strings.HasPrefix(line, DIFF_HEAD) {
|
if strings.HasPrefix(line, DIFF_HEAD) {
|
||||||
middle := -1
|
middle := -1
|
||||||
|
|
||||||
// Note: In case file name is surrounded by double quotes(it happens only in git-shell).
|
// Note: In case file name is surrounded by double quotes (it happens only in git-shell).
|
||||||
hasQuote := strings.Index(line, `\"`) > -1
|
// e.g. diff --git "a/xxx" "b/xxx"
|
||||||
|
hasQuote := line[len(DIFF_HEAD)] == '"'
|
||||||
if hasQuote {
|
if hasQuote {
|
||||||
line = strings.Replace(line, `\"`, `"`, -1)
|
|
||||||
middle = strings.Index(line, ` "b/`)
|
middle = strings.Index(line, ` "b/`)
|
||||||
} else {
|
} else {
|
||||||
middle = strings.Index(line, " b/")
|
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]
|
a := line[beg+2 : middle]
|
||||||
b := line[middle+3:]
|
b := line[middle+3:]
|
||||||
if hasQuote {
|
if hasQuote {
|
||||||
a = a[1 : len(a)-1]
|
a = string(git.UnescapeChars([]byte(a[1 : len(a)-1])))
|
||||||
b = b[1 : len(b)-1]
|
b = string(git.UnescapeChars([]byte(b[1 : len(b)-1])))
|
||||||
}
|
}
|
||||||
|
|
||||||
curFile = &DiffFile{
|
curFile = &DiffFile{
|
||||||
|
@ -30,7 +30,7 @@ type Tree struct {
|
|||||||
|
|
||||||
var escapeChar = []byte("\\")
|
var escapeChar = []byte("\\")
|
||||||
|
|
||||||
func unescapeChars(in []byte) []byte {
|
func UnescapeChars(in []byte) []byte {
|
||||||
if bytes.Index(in, escapeChar) == -1 {
|
if bytes.Index(in, escapeChar) == -1 {
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
@ -39,12 +39,11 @@ func unescapeChars(in []byte) []byte {
|
|||||||
isEscape := false
|
isEscape := false
|
||||||
out := make([]byte, 0, endIdx+1)
|
out := make([]byte, 0, endIdx+1)
|
||||||
for i := range in {
|
for i := range in {
|
||||||
if in[i] == '\\' && i != endIdx {
|
if in[i] == '\\' && !isEscape {
|
||||||
isEscape = !isEscape
|
isEscape = true
|
||||||
if isEscape {
|
continue
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
isEscape = false
|
||||||
out = append(out, in[i])
|
out = append(out, in[i])
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
@ -92,11 +91,12 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
|
|||||||
pos += step + 1 // Skip half of sha1.
|
pos += step + 1 // Skip half of sha1.
|
||||||
|
|
||||||
step = bytes.IndexByte(data[pos:], '\n')
|
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).
|
// In case entry name is surrounded by double quotes(it happens only in git-shell).
|
||||||
if entry.name[0] == '"' {
|
if data[pos] == '"' {
|
||||||
entry.name = string(unescapeChars(data[pos+1 : pos+step-1]))
|
entry.name = string(UnescapeChars(data[pos+1 : pos+step-1]))
|
||||||
|
} else {
|
||||||
|
entry.name = string(data[pos : pos+step])
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += step + 1
|
pos += step + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user