Skip to content

Commit b3b89a6

Browse files
authored
Merge branch 'main' into fix-repo-topic-edit
2 parents 93a2d40 + 7e3b7c2 commit b3b89a6

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

modules/typesniffer/typesniffer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ func DetectContentType(data []byte) SniffedType {
106106
}
107107
}
108108

109+
if strings.HasPrefix(ct, "audio/") && bytes.HasPrefix(data, []byte("ID3")) {
110+
// The MP3 detection is quite inaccurate, any content with "ID3" prefix will result in "audio/mpeg".
111+
// So remove the "ID3" prefix and detect again, if result is text, then it must be text content.
112+
// This works especially because audio files contain many unprintable/invalid characters like `0x00`
113+
ct2 := http.DetectContentType(data[3:])
114+
if strings.HasPrefix(ct2, "text/") {
115+
ct = ct2
116+
}
117+
}
118+
109119
return SniffedType{ct}
110120
}
111121

modules/typesniffer/typesniffer_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func TestIsAudio(t *testing.T) {
109109
mp3, _ := base64.StdEncoding.DecodeString("SUQzBAAAAAABAFRYWFgAAAASAAADbWFqb3JfYnJhbmQAbXA0MgBUWFhYAAAAEQAAA21pbm9yX3Zl")
110110
assert.True(t, DetectContentType(mp3).IsAudio())
111111
assert.False(t, DetectContentType([]byte("plain text")).IsAudio())
112+
113+
assert.True(t, DetectContentType([]byte("ID3Toy\000")).IsAudio())
114+
assert.True(t, DetectContentType([]byte("ID3Toy\n====\t* hi 🌞, ...")).IsText()) // test ID3 tag for plain text
115+
assert.True(t, DetectContentType([]byte("ID3Toy\n====\t* hi 🌞, ..."+"🌛"[0:2])).IsText()) // test ID3 tag with incomplete UTF8 char
112116
}
113117

114118
func TestDetectContentTypeFromReader(t *testing.T) {

templates/repo/issue/view_content/context_menu.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
{{else}}
1111
{{$referenceUrl = Printf "%s/files#%s" .ctxData.Issue.Link .item.HashTag}}
1212
{{end}}
13-
<a class="item context" data-clipboard-text-type="url" data-clipboard-text="{{AppSubUrl}}{{$referenceUrl}}">{{.ctxData.locale.Tr "repo.issues.context.copy_link"}}</a>
14-
<a class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.HashTag}}-raw">{{.ctxData.locale.Tr "repo.issues.context.quote_reply"}}</a>
13+
<div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{AppSubUrl}}{{$referenceUrl}}">{{.ctxData.locale.Tr "repo.issues.context.copy_link"}}</div>
14+
<div class="item context js-aria-clickable quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.HashTag}}-raw">{{.ctxData.locale.Tr "repo.issues.context.quote_reply"}}</div>
1515
{{if not .ctxData.UnitIssuesGlobalDisabled}}
16-
<a class="item context reference-issue" data-target="{{.item.HashTag}}-raw" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-poster-username="{{.item.Poster.Name}}" data-reference="{{$referenceUrl}}">{{.ctxData.locale.Tr "repo.issues.context.reference_issue"}}</a>
16+
<div class="item context js-aria-clickable reference-issue" data-target="{{.item.HashTag}}-raw" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-poster-username="{{.item.Poster.Name}}" data-reference="{{$referenceUrl}}">{{.ctxData.locale.Tr "repo.issues.context.reference_issue"}}</div>
1717
{{end}}
1818
{{if or .ctxData.Permission.IsAdmin .IsCommentPoster .ctxData.HasIssuesOrPullsWritePermission}}
1919
<div class="divider"></div>
20-
<a class="item context edit-content">{{.ctxData.locale.Tr "repo.issues.context.edit"}}</a>
20+
<div class="item context js-aria-clickable edit-content">{{.ctxData.locale.Tr "repo.issues.context.edit"}}</div>
2121
{{if .delete}}
22-
<a class="item context delete-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctxData.RepoLink}}/comments/{{.item.ID}}/delete" data-locale="{{.ctxData.locale.Tr "repo.issues.delete_comment_confirm"}}">{{.ctxData.locale.Tr "repo.issues.context.delete"}}</a>
22+
<div class="item context js-aria-clickable delete-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctxData.RepoLink}}/comments/{{.item.ID}}/delete" data-locale="{{.ctxData.locale.Tr "repo.issues.delete_comment_confirm"}}">{{.ctxData.locale.Tr "repo.issues.context.delete"}}</div>
2323
{{end}}
2424
{{end}}
2525
</div>

web_src/js/features/aria.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ function attachOneDropdownAria($dropdown) {
8484
if (e.key === 'Enter') {
8585
let $item = $dropdown.dropdown('get item', $dropdown.dropdown('get value'));
8686
if (!$item) $item = $menu.find('> .item.selected'); // when dropdown filters items by input, there is no "value", so query the "selected" item
87-
// if the selected item is clickable, then trigger the click event. in the future there could be a special CSS class for it.
88-
if ($item && $item.is('a')) $item[0].click();
87+
// if the selected item is clickable, then trigger the click event.
88+
// we can not click any item without check, because Fomantic code might also handle the Enter event. that would result in double click.
89+
if ($item && ($item.is('a') || $item.is('.js-aria-clickable'))) $item[0].click();
8990
}
9091
});
9192

0 commit comments

Comments
 (0)