@@ -11,7 +11,9 @@ import (
11
11
"encoding/json"
12
12
"fmt"
13
13
"regexp"
14
+ "strconv"
14
15
"strings"
16
+ "unicode/utf8"
15
17
16
18
"code.gitea.io/gitea/modules/git"
17
19
"code.gitea.io/gitea/modules/log"
@@ -143,7 +145,8 @@ type Comment struct {
143
145
RenderedContent string `xorm:"-"`
144
146
145
147
// Path represents the 4 lines of code cemented by this comment
146
- Patch string `xorm:"TEXT"`
148
+ Patch string `xorm:"-"`
149
+ PatchQuoted string `xorm:"TEXT patch"`
147
150
148
151
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
149
152
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -199,6 +202,33 @@ func (c *Comment) loadIssue(e Engine) (err error) {
199
202
return
200
203
}
201
204
205
+ // BeforeInsert will be invoked by XORM before inserting a record
206
+ func (c * Comment ) BeforeInsert () {
207
+ c .PatchQuoted = c .Patch
208
+ if ! utf8 .ValidString (c .Patch ) {
209
+ c .PatchQuoted = strconv .Quote (c .Patch )
210
+ }
211
+ }
212
+
213
+ // BeforeUpdate will be invoked by XORM before updating a record
214
+ func (c * Comment ) BeforeUpdate () {
215
+ c .PatchQuoted = c .Patch
216
+ if ! utf8 .ValidString (c .Patch ) {
217
+ c .PatchQuoted = strconv .Quote (c .Patch )
218
+ }
219
+ }
220
+
221
+ // AfterLoad is invoked from XORM after setting the values of all fields of this object.
222
+ func (c * Comment ) AfterLoad (session * xorm.Session ) {
223
+ c .Patch = c .PatchQuoted
224
+ if len (c .PatchQuoted ) > 0 && c .PatchQuoted [0 ] == '"' {
225
+ unquoted , err := strconv .Unquote (c .PatchQuoted )
226
+ if err == nil {
227
+ c .Patch = unquoted
228
+ }
229
+ }
230
+ }
231
+
202
232
func (c * Comment ) loadPoster (e Engine ) (err error ) {
203
233
if c .PosterID <= 0 || c .Poster != nil {
204
234
return nil
0 commit comments