Skip to content

Commit a88449f

Browse files
authored
Fix various problems (#37029)
1. Use "margin/padding inline" * Fix #37027 2. Make DetectWellKnownMimeType fallback to system mime types 3. Make catFileBatchCommunicator close pipes * Old behavior in 1.25: https://github.com/go-gitea/gitea/blob/release/v1.25/modules/git/batch_reader.go#L45-L55 * Try to fix #37028
1 parent 755d200 commit a88449f

3 files changed

Lines changed: 60 additions & 44 deletions

File tree

modules/git/catfile_batch_reader.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ import (
2222
var catFileBatchDebugWaitClose atomic.Int64
2323

2424
type catFileBatchCommunicator struct {
25-
cancel context.CancelFunc
25+
closeFunc func(err error)
2626
reqWriter io.Writer
2727
respReader *bufio.Reader
2828
debugGitCmd *gitcmd.Command
2929
}
3030

3131
func (b *catFileBatchCommunicator) Close() {
32-
if b.cancel != nil {
33-
b.cancel()
34-
b.cancel = nil
32+
if b.closeFunc != nil {
33+
b.closeFunc(nil)
34+
b.closeFunc = nil
3535
}
3636
}
3737

@@ -47,10 +47,19 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
4747
}
4848
stdPipeClose()
4949
}
50+
closeFunc := func(err error) {
51+
ctxCancel(err)
52+
pipeClose()
53+
}
54+
return newCatFileBatchWithCloseFunc(ctx, repoPath, cmdCatFile, stdinWriter, stdoutReader, closeFunc)
55+
}
5056

51-
ret = &catFileBatchCommunicator{
57+
func newCatFileBatchWithCloseFunc(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command,
58+
stdinWriter gitcmd.PipeWriter, stdoutReader gitcmd.PipeReader, closeFunc func(err error),
59+
) *catFileBatchCommunicator {
60+
ret := &catFileBatchCommunicator{
5261
debugGitCmd: cmdCatFile,
53-
cancel: func() { ctxCancel(nil) },
62+
closeFunc: closeFunc,
5463
reqWriter: stdinWriter,
5564
respReader: bufio.NewReaderSize(stdoutReader, 32*1024), // use a buffered reader for rich operations
5665
}
@@ -60,8 +69,7 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
6069
log.Error("Unable to start git command %v: %v", cmdCatFile.LogString(), err)
6170
// ideally here it should return the error, but it would require refactoring all callers
6271
// so just return a dummy communicator that does nothing, almost the same behavior as before, not bad
63-
ctxCancel(err)
64-
pipeClose()
72+
closeFunc(err)
6573
return ret
6674
}
6775

@@ -70,8 +78,7 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
7078
if err != nil && !errors.Is(err, context.Canceled) {
7179
log.Error("cat-file --batch command failed in repo %s, error: %v", repoPath, err)
7280
}
73-
ctxCancel(err)
74-
pipeClose()
81+
closeFunc(err)
7582
}()
7683

7784
return ret

modules/public/mime_types.go

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,36 @@
44
package public
55

66
import (
7+
"mime"
78
"strings"
9+
"sync"
810
)
911

10-
// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`, see the comment of DetectWellKnownMimeType
11-
var wellKnownMimeTypesLower = map[string]string{
12-
".avif": "image/avif",
13-
".css": "text/css; charset=utf-8",
14-
".gif": "image/gif",
15-
".htm": "text/html; charset=utf-8",
16-
".html": "text/html; charset=utf-8",
17-
".jpeg": "image/jpeg",
18-
".jpg": "image/jpeg",
19-
".js": "text/javascript; charset=utf-8",
20-
".json": "application/json",
21-
".mjs": "text/javascript; charset=utf-8",
22-
".pdf": "application/pdf",
23-
".png": "image/png",
24-
".svg": "image/svg+xml",
25-
".wasm": "application/wasm",
26-
".webp": "image/webp",
27-
".xml": "text/xml; charset=utf-8",
12+
// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`,
13+
// see the comment of DetectWellKnownMimeType
14+
var wellKnownMimeTypesLower = sync.OnceValue(func() map[string]string {
15+
return map[string]string{
16+
".avif": "image/avif",
17+
".css": "text/css; charset=utf-8",
18+
".gif": "image/gif",
19+
".htm": "text/html; charset=utf-8",
20+
".html": "text/html; charset=utf-8",
21+
".jpeg": "image/jpeg",
22+
".jpg": "image/jpeg",
23+
".js": "text/javascript; charset=utf-8",
24+
".json": "application/json",
25+
".mjs": "text/javascript; charset=utf-8",
26+
".pdf": "application/pdf",
27+
".png": "image/png",
28+
".svg": "image/svg+xml",
29+
".wasm": "application/wasm",
30+
".webp": "image/webp",
31+
".xml": "text/xml; charset=utf-8",
2832

29-
// well, there are some types missing from the builtin list
30-
".txt": "text/plain; charset=utf-8",
31-
}
33+
// well, there are some types missing from the builtin list
34+
".txt": "text/plain; charset=utf-8",
35+
}
36+
})
3237

3338
// DetectWellKnownMimeType will return the mime-type for a well-known file ext name
3439
// The purpose of this function is to bypass the unstable behavior of Golang's mime.TypeByExtension
@@ -38,5 +43,8 @@ var wellKnownMimeTypesLower = map[string]string{
3843
// DetectWellKnownMimeType makes the Content-Type for well-known files stable.
3944
func DetectWellKnownMimeType(ext string) string {
4045
ext = strings.ToLower(ext)
41-
return wellKnownMimeTypesLower[ext]
46+
if s, ok := wellKnownMimeTypesLower()[ext]; ok {
47+
return s
48+
}
49+
return mime.TypeByExtension(ext)
4250
}

web_src/css/markup/content.css

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
.markup .anchor {
2626
float: left;
27-
padding-right: 4px;
28-
margin-left: -20px;
27+
padding-inline-end: 4px;
28+
margin-inline-start: -20px;
2929
color: inherit;
3030
}
3131

@@ -151,7 +151,7 @@ In markup content, we always use bottom margin for all elements */
151151

152152
.markup ul,
153153
.markup ol {
154-
padding-left: 2em;
154+
padding-inline-start: 2em;
155155
}
156156

157157
.markup ul.no-list,
@@ -173,13 +173,14 @@ In markup content, we always use bottom margin for all elements */
173173
}
174174

175175
.markup .task-list-item input[type="checkbox"] {
176-
margin: 0 .6em .25em -1.4em;
176+
margin-bottom: 0.25em;
177+
margin-inline: -1.4em 0.6em;
177178
vertical-align: middle;
178179
padding: 0;
179180
}
180181

181182
.markup .task-list-item input[type="checkbox"] + p {
182-
margin-left: -0.2em;
183+
margin-inline-start: -0.2em;
183184
display: inline;
184185
}
185186

@@ -192,7 +193,7 @@ In markup content, we always use bottom margin for all elements */
192193
}
193194

194195
.markup input[type="checkbox"] {
195-
margin-right: .25em;
196+
margin-inline-end: .25em;
196197
margin-bottom: .25em;
197198
cursor: default;
198199
opacity: 1 !important; /* override fomantic on edit preview */
@@ -239,7 +240,7 @@ In markup content, we always use bottom margin for all elements */
239240
}
240241

241242
.markup blockquote {
242-
margin-left: 0;
243+
margin-inline-start: 0;
243244
padding: 0 15px;
244245
color: var(--color-text-light-2);
245246
border-left: 0.25em solid var(--color-secondary);
@@ -318,12 +319,12 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
318319

319320
.markup img[align="right"],
320321
.markup video[align="right"] {
321-
padding-left: 20px;
322+
padding-inline-start: 20px;
322323
}
323324

324325
.markup img[align="left"],
325326
.markup video[align="left"] {
326-
padding-right: 28px;
327+
padding-inline-end: 28px;
327328
}
328329

329330
.markup span.frame {
@@ -395,7 +396,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
395396
.markup span.float-left {
396397
display: block;
397398
float: left;
398-
margin-right: 13px;
399+
margin-inline-end: 13px;
399400
overflow: hidden;
400401
}
401402

@@ -406,7 +407,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
406407
.markup span.float-right {
407408
display: block;
408409
float: right;
409-
margin-left: 13px;
410+
margin-inline-start: 13px;
410411
overflow: hidden;
411412
}
412413

@@ -508,7 +509,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
508509
.markup .ui.list .list,
509510
.markup ol.ui.list ol,
510511
.markup ul.ui.list ul {
511-
padding-left: 2em;
512+
padding-inline-start: 2em;
512513
}
513514

514515
.markup details.frontmatter-content summary {

0 commit comments

Comments
 (0)