@ -18,7 +18,6 @@ import (
"os/exec"
"os/exec"
"regexp"
"regexp"
"sort"
"sort"
"strconv"
"strings"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models"
@ -570,41 +569,29 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
break
break
}
}
var middle int
// 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).
// e.g. diff --git "a/xxx" "b/xxx"
// e.g. diff --git "a/xxx" "b/xxx"
hasQuote := line [ len ( cmdDiffHead ) ] == '"'
var a string
if hasQuote {
var b string
middle = strings . Index ( line , ` "b/ ` )
rd := strings . NewReader ( line [ len ( cmdDiffHead ) : ] )
char , _ := rd . ReadByte ( )
_ = rd . UnreadByte ( )
if char == '"' {
fmt . Fscanf ( rd , "%q " , & a )
} else {
} else {
middle = strings . Index ( line , " b/" )
fmt . Fscanf ( rd , "%s " , & a )
}
beg := len ( cmdDiffHead )
a := line [ beg + 2 : middle ]
b := line [ middle + 3 : ]
if hasQuote {
// Keep the entire string in double quotes for now
a = line [ beg : middle ]
b = line [ middle + 1 : ]
var err error
a , err = strconv . Unquote ( a )
if err != nil {
return nil , fmt . Errorf ( "Unquote: %v" , err )
}
}
b , err = strconv . Unquote ( b )
char , _ = rd . ReadByte ( )
if err != nil {
_ = rd . UnreadByte ( )
return nil , fmt . Errorf ( "Unquote: %v" , err )
if char == '"' {
fmt . Fscanf ( rd , "%q" , & b )
} else {
fmt . Fscanf ( rd , "%s" , & b )
}
}
// Now remove the /a /b
a = a [ 2 : ]
a = a [ 2 : ]
b = b [ 2 : ]
b = b [ 2 : ]
}
curFile = & DiffFile {
curFile = & DiffFile {
Name : b ,
Name : b ,
OldName : a ,
OldName : a ,