Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Fix markdown preview $$ support (go-gitea#31514)
  Add Passkey login support (go-gitea#31504)
  Use stable version of fabric (go-gitea#31526)
  Always use HTML attributes for avatar size (go-gitea#31509)
  Add initial typescript config and use it for eslint,vitest,playwright (go-gitea#31186)
  Support legacy _links LFS batch responses (go-gitea#31513)
  Fix JS error with disabled attachment and easymde (go-gitea#31511)
  • Loading branch information
zjjhot committed Jul 1, 2024
2 parents b9bbd74 + 3bd87fb commit e9b0046
Show file tree
Hide file tree
Showing 44 changed files with 549 additions and 144 deletions.
31 changes: 29 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ ignorePatterns:
- /web_src/fomantic
- /public/assets/js

parser: "@typescript-eslint/parser"

parserOptions:
sourceType: module
ecmaVersion: latest
project: true
extraFileExtensions: [".vue"]

settings:
import/extensions: [".js", ".ts"]
import/parsers:
"@typescript-eslint/parser": [".js", ".ts"]
import/resolver:
typescript: true

plugins:
- "@eslint-community/eslint-plugin-eslint-comments"
Expand Down Expand Up @@ -103,6 +114,22 @@ overrides:
- files: ["web_src/js/modules/fetch.js", "web_src/js/standalone/**/*"]
rules:
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]
- files: ["**/*.vue"]
plugins:
- eslint-plugin-vue
- eslint-plugin-vue-scoped-css
extends:
- plugin:vue/vue3-recommended
- plugin:vue-scoped-css/vue3-recommended
rules:
vue/attributes-order: [0]
vue/html-closing-bracket-spacing: [2, {startTag: never, endTag: never, selfClosingTag: never}]
vue/max-attributes-per-line: [0]
vue/singleline-html-element-content-newline: [0]
- files: ["tests/e2e/**"]
plugins:
- eslint-plugin-playwright
extends: plugin:playwright/recommended

rules:
"@eslint-community/eslint-comments/disable-enable-pair": [2]
Expand Down Expand Up @@ -264,7 +291,7 @@ rules:
i/no-internal-modules: [0]
i/no-mutable-exports: [0]
i/no-named-as-default-member: [0]
i/no-named-as-default: [2]
i/no-named-as-default: [0]
i/no-named-default: [0]
i/no-named-export: [0]
i/no-namespace: [0]
Expand All @@ -274,7 +301,7 @@ rules:
i/no-restricted-paths: [0]
i/no-self-import: [2]
i/no-unassigned-import: [0]
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$", ^vitest/]}]
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$"]}]
i/no-unused-modules: [2, {unusedExports: true}]
i/no-useless-path-segments: [2, {commonjs: true}]
i/no-webpack-loader-syntax: [2]
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,13 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig

.PHONY: lint-js
lint-js: node_modules
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES)
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
npx tsc

.PHONY: lint-js-fix
lint-js-fix: node_modules
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES) --fix
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
npx tsc

.PHONY: lint-css
lint-css: node_modules
Expand Down Expand Up @@ -967,7 +969,7 @@ generate-gitignore:

.PHONY: generate-images
generate-images: | node_modules
npm install --no-save fabric@6.0.0-beta20 imagemin-zopfli@7
npm install --no-save fabric@6 imagemin-zopfli@7
node tools/generate-images.js $(TAGS)

.PHONY: generate-manpage
Expand Down
2 changes: 1 addition & 1 deletion models/auth/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func DeleteCredential(ctx context.Context, id, userID int64) (bool, error) {
return had > 0, err
}

// WebAuthnCredentials implementns the webauthn.User interface
// WebAuthnCredentials implements the webauthn.User interface
func WebAuthnCredentials(ctx context.Context, userID int64) ([]webauthn.Credential, error) {
dbCreds, err := GetWebAuthnCredentialsByUID(ctx, userID)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/auth/webauthn/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Init() {
RPID: setting.Domain,
RPOrigins: []string{appURL},
AuthenticatorSelection: protocol.AuthenticatorSelection{
UserVerification: "discouraged",
UserVerification: protocol.VerificationDiscouraged,
},
AttestationPreference: protocol.PreferDirectAttestation,
},
Expand Down Expand Up @@ -66,7 +66,7 @@ func (u *User) WebAuthnIcon() string {
return (*user_model.User)(u).AvatarLink(db.DefaultContext)
}

// WebAuthnCredentials implementns the webauthn.User interface
// WebAuthnCredentials implements the webauthn.User interface
func (u *User) WebAuthnCredentials() []webauthn.Credential {
dbCreds, err := auth.GetWebAuthnCredentialsByUID(db.DefaultContext, u.ID)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions modules/lfs/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (c *HTTPClient) performOperation(ctx context.Context, objects []Pointer, dc
}
} else {
link, ok := object.Actions["download"]
if !ok {
// no actions block in response, try legacy response schema
link, ok = object.Links["download"]
}
if !ok {
log.Debug("%+v", object)
return errors.New("missing action 'download'")
Expand Down
16 changes: 16 additions & 0 deletions modules/lfs/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func lfsTestRoundtripHandler(req *http.Request) *http.Response {
},
},
}
} else if strings.Contains(url, "legacy-batch-request-download") {
batchResponse = &BatchResponse{
Transfer: "dummy",
Objects: []*ObjectResponse{
{
Links: map[string]*Link{
"download": {},
},
},
},
}
} else if strings.Contains(url, "valid-batch-request-upload") {
batchResponse = &BatchResponse{
Transfer: "dummy",
Expand Down Expand Up @@ -229,6 +240,11 @@ func TestHTTPClientDownload(t *testing.T) {
endpoint: "https://unknown-actions-map.io",
expectederror: "missing action 'download'",
},
// case 11
{
endpoint: "https://legacy-batch-request-download.io",
expectederror: "",
},
}

for n, c := range cases {
Expand Down
1 change: 1 addition & 0 deletions modules/lfs/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type BatchResponse struct {
type ObjectResponse struct {
Pointer
Actions map[string]*Link `json:"actions,omitempty"`
Links map[string]*Link `json:"_links,omitempty"`
Error *ObjectError `json:"error,omitempty"`
}

Expand Down
8 changes: 8 additions & 0 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ func TestMathBlock(t *testing.T) {
"$a$ ($b$) [$c$] {$d$}",
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
},
{
"$$a$$ test",
`<p><code class="language-math display is-loading">a</code> test</p>` + nl,
},
{
"test $$a$$",
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
},
}

for _, test := range testcases {
Expand Down
6 changes: 6 additions & 0 deletions modules/markup/markdown/math/block_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func (b *blockParser) Open(parent ast.Node, reader text.Reader, pc parser.Contex
}
idx := bytes.Index(line[pos+2:], endBytes)
if idx >= 0 {
// for case $$ ... $$ any other text
for i := pos + idx + 4; i < len(line); i++ {
if line[i] != ' ' && line[i] != '\n' {
return nil, parser.NoChildren
}
}
segment.Stop = segment.Start + idx + 2
reader.Advance(segment.Len() - 1)
segment.Start += 2
Expand Down
31 changes: 31 additions & 0 deletions modules/markup/markdown/math/inline_block_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package math

import (
"github.com/yuin/goldmark/ast"
)

// InlineBlock represents inline math e.g. $$...$$
type InlineBlock struct {
Inline
}

// InlineBlock implements InlineBlock.
func (n *InlineBlock) InlineBlock() {}

// KindInlineBlock is the kind for math inline block
var KindInlineBlock = ast.NewNodeKind("MathInlineBlock")

// Kind returns KindInlineBlock
func (n *InlineBlock) Kind() ast.NodeKind {
return KindInlineBlock
}

// NewInlineBlock creates a new ast math inline block node
func NewInlineBlock() *InlineBlock {
return &InlineBlock{
Inline{},
}
}
30 changes: 26 additions & 4 deletions modules/markup/markdown/math/inline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ var defaultInlineDollarParser = &inlineParser{
end: []byte{'$'},
}

var defaultDualDollarParser = &inlineParser{
start: []byte{'$', '$'},
end: []byte{'$', '$'},
}

// NewInlineDollarParser returns a new inline parser
func NewInlineDollarParser() parser.InlineParser {
return defaultInlineDollarParser
}

func NewInlineDualDollarParser() parser.InlineParser {
return defaultDualDollarParser
}

var defaultInlineBracketParser = &inlineParser{
start: []byte{'\\', '('},
end: []byte{'\\', ')'},
Expand All @@ -38,7 +47,7 @@ func NewInlineBracketParser() parser.InlineParser {

// Trigger triggers this parser on $ or \
func (parser *inlineParser) Trigger() []byte {
return parser.start[0:1]
return parser.start
}

func isPunctuation(b byte) bool {
Expand Down Expand Up @@ -88,7 +97,11 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
break
}
suceedingCharacter := line[pos]
if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') && !isBracket(suceedingCharacter) {
// check valid ending character
if !isPunctuation(suceedingCharacter) &&
!(suceedingCharacter == ' ') &&
!(suceedingCharacter == '\n') &&
!isBracket(suceedingCharacter) {
return nil
}
if line[ender-1] != '\\' {
Expand All @@ -101,12 +114,21 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.

block.Advance(opener)
_, pos := block.Position()
node := NewInline()
var node ast.Node
if parser == defaultDualDollarParser {
node = NewInlineBlock()
} else {
node = NewInline()
}
segment := pos.WithStop(pos.Start + ender - opener)
node.AppendChild(node, ast.NewRawTextSegment(segment))
block.Advance(ender - opener + len(parser.end))

trimBlock(node, block)
if parser == defaultDualDollarParser {
trimBlock(&(node.(*InlineBlock)).Inline, block)
} else {
trimBlock(node.(*Inline), block)
}
return node
}

Expand Down
7 changes: 6 additions & 1 deletion modules/markup/markdown/math/inline_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func NewInlineRenderer() renderer.NodeRenderer {

func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
if entering {
_, _ = w.WriteString(`<code class="language-math is-loading">`)
extraClass := ""
if _, ok := n.(*InlineBlock); ok {
extraClass = "display "
}
_, _ = w.WriteString(`<code class="language-math ` + extraClass + `is-loading">`)
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
segment := c.(*ast.Text).Segment
value := util.EscapeHTML(segment.Value(source))
Expand All @@ -43,4 +47,5 @@ func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Nod
// RegisterFuncs registers the renderer for inline math nodes
func (r *InlineRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
reg.Register(KindInline, r.renderInline)
reg.Register(KindInlineBlock, r.renderInline)
}
3 changes: 2 additions & 1 deletion modules/markup/markdown/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (e *Extension) Extend(m goldmark.Markdown) {
util.Prioritized(NewInlineBracketParser(), 501),
}
if e.parseDollarInline {
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 501))
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 503),
util.Prioritized(NewInlineDualDollarParser(), 502))
}
m.Parser().AddOptions(parser.WithInlineParsers(inlines...))

Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ sspi_auth_failed = SSPI authentication failed
password_pwned = The password you chose is on a <a target="_blank" rel="noopener noreferrer" href="https://haveibeenpwned.com/Passwords">list of stolen passwords</a> previously exposed in public data breaches. Please try again with a different password and consider changing this password elsewhere too.
password_pwned_err = Could not complete request to HaveIBeenPwned
last_admin = You cannot remove the last admin. There must be at least one admin.
signin_passkey = Sign in with a passkey
[mail]
view_it_on = View it on %s
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ sspi_auth_failed=Falhou a autenticação SSPI
password_pwned=A senha utilizada está numa <a target="_blank" rel="noopener noreferrer" href="https://haveibeenpwned.com/Passwords">lista de senhas roubadas</a> anteriormente expostas em fugas de dados públicas. Tente novamente com uma senha diferente e considere também mudar esta senha nos outros sítios.
password_pwned_err=Não foi possível completar o pedido ao HaveIBeenPwned
last_admin=Não pode remover o último administrador. Tem que existir pelo menos um administrador.
signin_passkey=Iniciar sessão com uma passkey

[mail]
view_it_on=Ver em %s
Expand Down
Loading

0 comments on commit e9b0046

Please sign in to comment.