Skip to content

Commit 7a1cc34

Browse files
committed
Merge branch 'main' into lunny/improve_notification
2 parents fd17f05 + 4fc626d commit 7a1cc34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1003
-1651
lines changed

models/git/lfs.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ type LFSMetaObject struct {
112112
ID int64 `xorm:"pk autoincr"`
113113
lfs.Pointer `xorm:"extends"`
114114
RepositoryID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
115-
Existing bool `xorm:"-"`
116115
CreatedUnix timeutil.TimeStamp `xorm:"created"`
117116
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
118117
}
@@ -146,7 +145,6 @@ func NewLFSMetaObject(ctx context.Context, repoID int64, p lfs.Pointer) (*LFSMet
146145
if err != nil {
147146
return nil, err
148147
} else if exist {
149-
m.Existing = true
150148
return m, committer.Commit()
151149
}
152150

modules/markup/html_node.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ func processNodeA(ctx *RenderContext, node *html.Node) {
6363

6464
func visitNodeImg(ctx *RenderContext, img *html.Node) (next *html.Node) {
6565
next = img.NextSibling
66+
attrSrc, hasLazy := "", false
6667
for i, imgAttr := range img.Attr {
68+
hasLazy = hasLazy || imgAttr.Key == "loading" && imgAttr.Val == "lazy"
6769
if imgAttr.Key != "src" {
70+
attrSrc = imgAttr.Val
6871
continue
6972
}
7073

7174
imgSrcOrigin := imgAttr.Val
7275
isLinkable := imgSrcOrigin != "" && !strings.HasPrefix(imgSrcOrigin, "data:")
7376

7477
// By default, the "<img>" tag should also be clickable,
75-
// because frontend use `<img>` to paste the re-scaled image into the markdown,
76-
// so it must match the default markdown image behavior.
78+
// because frontend uses `<img>` to paste the re-scaled image into the Markdown,
79+
// so it must match the default Markdown image behavior.
7780
cnt := 0
7881
for p := img.Parent; isLinkable && p != nil && cnt < 2; p = p.Parent {
7982
if hasParentAnchor := p.Type == html.ElementNode && p.Data == "a"; hasParentAnchor {
@@ -98,6 +101,9 @@ func visitNodeImg(ctx *RenderContext, img *html.Node) (next *html.Node) {
98101
imgAttr.Val = camoHandleLink(imgAttr.Val)
99102
img.Attr[i] = imgAttr
100103
}
104+
if !RenderBehaviorForTesting.DisableAdditionalAttributes && !hasLazy && !strings.HasPrefix(attrSrc, "data:") {
105+
img.Attr = append(img.Attr, html.Attribute{Key: "loading", Val: "lazy"})
106+
}
101107
return next
102108
}
103109

modules/markup/markdown/markdown_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestRender_StandardLinks(t *testing.T) {
4747
func TestRender_Images(t *testing.T) {
4848
setting.AppURL = AppURL
4949

50-
test := func(input, expected string) {
50+
render := func(input, expected string) {
5151
buffer, err := markdown.RenderString(markup.NewTestRenderContext(FullURL), input)
5252
assert.NoError(t, err)
5353
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
@@ -59,27 +59,32 @@ func TestRender_Images(t *testing.T) {
5959
result := util.URLJoin(FullURL, url)
6060
// hint: With Markdown v2.5.2, there is a new syntax: [link](URL){:target="_blank"} , but we do not support it now
6161

62-
test(
62+
render(
6363
"!["+title+"]("+url+")",
6464
`<p><a href="`+result+`" target="_blank" rel="nofollow noopener"><img src="`+result+`" alt="`+title+`"/></a></p>`)
6565

66-
test(
66+
render(
6767
"[["+title+"|"+url+"]]",
6868
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" title="`+title+`" alt="`+title+`"/></a></p>`)
69-
test(
69+
render(
7070
"[!["+title+"]("+url+")]("+href+")",
7171
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
7272

73-
test(
73+
render(
7474
"!["+title+"]("+url+")",
7575
`<p><a href="`+result+`" target="_blank" rel="nofollow noopener"><img src="`+result+`" alt="`+title+`"/></a></p>`)
7676

77-
test(
77+
render(
7878
"[["+title+"|"+url+"]]",
7979
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" title="`+title+`" alt="`+title+`"/></a></p>`)
80-
test(
80+
render(
8181
"[!["+title+"]("+url+")]("+href+")",
8282
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
83+
84+
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, false)()
85+
render(
86+
"<a><img src='a.jpg'></a>", // by the way, empty "a" tag will be removed
87+
`<p dir="auto"><img src="http://localhost:3000/user13/repo11/a.jpg" loading="lazy"/></p>`)
8388
}
8489

8590
func TestTotal_RenderString(t *testing.T) {

modules/markup/sanitizer_default.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
5252

5353
policy.AllowAttrs("src", "autoplay", "controls").OnElements("video")
5454

55+
policy.AllowAttrs("loading").OnElements("img")
56+
5557
// Allow generally safe attributes (reference: https://github.com/jch/html-pipeline)
5658
generalSafeAttrs := []string{
5759
"abbr", "accept", "accept-charset",

modules/structs/repo_file.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func (o *UpdateFileOptions) Branch() string {
6666
return o.FileOptions.BranchName
6767
}
6868

69+
// FIXME: ChangeFileOperation.SHA is NOT required for update or delete if last commit is provided in the options.
70+
6971
// ChangeFileOperation for creating, updating or deleting a file
7072
type ChangeFileOperation struct {
7173
// indicates what to do with the file

options/locale/locale_en-US.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ editor.update = Update %s
13541354
editor.delete = Delete %s
13551355
editor.patch = Apply Patch
13561356
editor.patching = Patching:
1357-
editor.fail_to_apply_patch = Unable to apply patch "%s"
1357+
editor.fail_to_apply_patch = Unable to apply patch
13581358
editor.new_patch = New Patch
13591359
editor.commit_message_desc = Add an optional extended description…
13601360
editor.signoff_desc = Add a Signed-off-by trailer by the committer at the end of the commit log message.
@@ -1374,17 +1374,14 @@ editor.branch_already_exists = Branch "%s" already exists in this repository.
13741374
editor.directory_is_a_file = Directory name "%s" is already used as a filename in this repository.
13751375
editor.file_is_a_symlink = `"%s" is a symbolic link. Symbolic links cannot be edited in the web editor`
13761376
editor.filename_is_a_directory = Filename "%s" is already used as a directory name in this repository.
1377-
editor.file_editing_no_longer_exists = The file being edited, "%s", no longer exists in this repository.
1378-
editor.file_deleting_no_longer_exists = The file being deleted, "%s", no longer exists in this repository.
1377+
editor.file_modifying_no_longer_exists = The file being modified, "%s", no longer exists in this repository.
13791378
editor.file_changed_while_editing = The file contents have changed since you started editing. <a target="_blank" rel="noopener noreferrer" href="%s">Click here</a> to see them or <strong>Commit Changes again</strong> to overwrite them.
13801379
editor.file_already_exists = A file named "%s" already exists in this repository.
13811380
editor.commit_id_not_matching = The Commit ID does not match the ID when you began editing. Commit into a patch branch and then merge.
13821381
editor.push_out_of_date = The push appears to be out of date.
13831382
editor.commit_empty_file_header = Commit an empty file
13841383
editor.commit_empty_file_text = The file you're about to commit is empty. Proceed?
13851384
editor.no_changes_to_show = There are no changes to show.
1386-
editor.fail_to_update_file = Failed to update/create file "%s".
1387-
editor.fail_to_update_file_summary = Error Message:
13881385
editor.push_rejected_no_message = The change was rejected by the server without a message. Please check Git Hooks.
13891386
editor.push_rejected = The change was rejected by the server. Please check Git Hooks.
13901387
editor.push_rejected_summary = Full Rejection Message:
@@ -1398,6 +1395,8 @@ editor.user_no_push_to_branch = User cannot push to branch
13981395
editor.require_signed_commit = Branch requires a signed commit
13991396
editor.cherry_pick = Cherry-pick %s onto:
14001397
editor.revert = Revert %s onto:
1398+
editor.failed_to_commit = Failed to commit changes.
1399+
editor.failed_to_commit_summary = Error Message:
14011400
14021401
commits.desc = Browse source code change history.
14031402
commits.commits = Commits

routers/api/v1/repo/file.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ func ChangeFiles(ctx *context.APIContext) {
470470
ctx.APIError(http.StatusUnprocessableEntity, err)
471471
return
472472
}
473+
// FIXME: actually now we support more operations like "rename", "upload"
474+
// FIXME: ChangeFileOperation.SHA is NOT required for update or delete if last commit is provided in the options.
475+
// Need to fully fix them in API
473476
changeRepoFile := &files_service.ChangeRepoFile{
474477
Operation: file.Operation,
475478
TreePath: file.Path,

routers/web/repo/cherry_pick.go

Lines changed: 0 additions & 193 deletions
This file was deleted.

0 commit comments

Comments
 (0)