Body: "first old line",
OldLineNum: 1,
NewLineNum: 0,
+ }, {
+ Path: "iso-8859-1.txt",
+ Body: "this line contains a non-utf-8 character",
+ OldLineNum: 0,
+ NewLineNum: 1,
},
},
})
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.EqualValues(t, "PENDING", review.State)
- assert.EqualValues(t, 2, review.CodeCommentsCount)
+ assert.EqualValues(t, 3, review.CodeCommentsCount)
// test SubmitPullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token), &api.SubmitPullReviewOptions{
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.EqualValues(t, "APPROVED", review.State)
- assert.EqualValues(t, 2, review.CodeCommentsCount)
+ assert.EqualValues(t, 3, review.CodeCommentsCount)
// test DeletePullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
import (
"fmt"
"regexp"
+ "strconv"
"strings"
+ "unicode/utf8"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
RenderedContent string `xorm:"-"`
// Path represents the 4 lines of code cemented by this comment
- Patch string `xorm:"TEXT"`
+ Patch string `xorm:"-"`
+ PatchQuoted string `xorm:"TEXT patch"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
return
}
+// BeforeInsert will be invoked by XORM before inserting a record
+func (c *Comment) BeforeInsert() {
+ c.PatchQuoted = c.Patch
+ if !utf8.ValidString(c.Patch) {
+ c.PatchQuoted = strconv.Quote(c.Patch)
+ }
+}
+
+// BeforeUpdate will be invoked by XORM before updating a record
+func (c *Comment) BeforeUpdate() {
+ c.PatchQuoted = c.Patch
+ if !utf8.ValidString(c.Patch) {
+ c.PatchQuoted = strconv.Quote(c.Patch)
+ }
+}
+
+// AfterLoad is invoked from XORM after setting the values of all fields of this object.
+func (c *Comment) AfterLoad(session *xorm.Session) {
+ c.Patch = c.PatchQuoted
+ if len(c.PatchQuoted) > 0 && c.PatchQuoted[0] == '"' {
+ unquoted, err := strconv.Unquote(c.PatchQuoted)
+ if err == nil {
+ c.Patch = unquoted
+ }
+ }
+}
+
func (c *Comment) loadPoster(e Engine) (err error) {
if c.PosterID <= 0 || c.Poster != nil {
return nil