diff --git a/Makefile b/Makefile index 3b7b5da857..1cdc550d29 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.6.0 # renovate: datasource=go GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.58.1 # renovate: datasource=go GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 # renovate: datasource=go MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1 # renovate: datasource=go -SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.6-0.20240201115257-bcc7c78b7786 # renovate: datasource=go +SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0 # renovate: datasource=go GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 # renovate: datasource=go diff --git a/cmd/hook.go b/cmd/hook.go index 4f73f8e2bc..f8184f9697 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -316,12 +316,12 @@ func runHookUpdate(c *cli.Context) error { return nil } - // Deletion of the ref means that the new commit ID is only composed of '0'. - if strings.ContainsFunc(newCommitID, func(e rune) bool { return e != '0' }) { - return nil + // Empty new commit ID means deletion. + if git.IsEmptyCommitID(newCommitID, nil) { + return fail(ctx, fmt.Sprintf("The deletion of %s is skipped as it's an internal reference.", refFullName), "") } - return fail(ctx, fmt.Sprintf("The deletion of %s is skipped as it's an internal reference.", refFullName), "") + return nil } func runHookPostReceive(c *cli.Context) error { @@ -405,8 +405,7 @@ Forgejo or set your environment appropriately.`, "") newCommitIDs[count] = string(fields[1]) refFullNames[count] = git.RefName(fields[2]) - commitID, _ := git.NewIDFromString(newCommitIDs[count]) - if refFullNames[count] == git.BranchPrefix+"master" && !commitID.IsZero() && count == total { + if refFullNames[count] == git.BranchPrefix+"master" && !git.IsEmptyCommitID(newCommitIDs[count], nil) && count == total { masterPushed = true } count++ @@ -697,8 +696,7 @@ Forgejo or set your environment appropriately.`, "") if err != nil { return err } - commitID, _ := git.NewIDFromString(rs.OldOID) - if !commitID.IsZero() { + if !git.IsEmptyCommitID(rs.OldOID, nil) { err = writeDataPktLine(ctx, os.Stdout, []byte("option old-oid "+rs.OldOID)) if err != nil { return err diff --git a/models/repo/repo.go b/models/repo/repo.go index 8af38f6248..6ab4af7990 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -332,7 +332,7 @@ func (repo *Repository) HTMLURL() string { // CommitLink make link to by commit full ID // note: won't check whether it's an right id func (repo *Repository) CommitLink(commitID string) (result string) { - if git.IsEmptyCommitID(commitID) { + if git.IsEmptyCommitID(commitID, nil) { result = "" } else { result = repo.Link() + "/commit/" + url.PathEscape(commitID) diff --git a/modules/git/object_format.go b/modules/git/object_format.go index c2fcf4c063..2b462589a3 100644 --- a/modules/git/object_format.go +++ b/modules/git/object_format.go @@ -122,6 +122,7 @@ func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) Object var ( Sha1ObjectFormat ObjectFormat = Sha1ObjectFormatImpl{} Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{} + // any addition must be reflected in IsEmptyCommitID ) var SupportedObjectFormats = []ObjectFormat{ diff --git a/modules/git/object_id.go b/modules/git/object_id.go index 4f8c39ee1d..26736bb766 100644 --- a/modules/git/object_id.go +++ b/modules/git/object_id.go @@ -79,17 +79,25 @@ func NewIDFromString(hexHash string) (ObjectID, error) { return theObjectFormat.MustID(b), nil } -func IsEmptyCommitID(commitID string) bool { +// IsEmptyCommitID checks if an hexadecimal string represents an empty commit according to git (only '0'). +// If objectFormat is not nil, the length will be checked as well (otherwise the lenght must match the sha1 or sha256 length). +func IsEmptyCommitID(commitID string, objectFormat ObjectFormat) bool { if commitID == "" { return true } - - id, err := NewIDFromString(commitID) - if err != nil { + if objectFormat == nil { + if Sha1ObjectFormat.FullLength() != len(commitID) && Sha256ObjectFormat.FullLength() != len(commitID) { + return false + } + } else if objectFormat.FullLength() != len(commitID) { return false } - - return id.IsZero() + for _, c := range commitID { + if c != '0' { + return false + } + } + return true } // ComputeBlobHash compute the hash for a given blob content diff --git a/modules/git/object_id_test.go b/modules/git/object_id_test.go index 6f365d6b19..00a24e3981 100644 --- a/modules/git/object_id_test.go +++ b/modules/git/object_id_test.go @@ -23,3 +23,27 @@ func TestIsValidSHAPattern(t *testing.T) { assert.Equal(t, "d5c6407415d85df49592672aa421aed39b9db5e3", ComputeBlobHash(Sha1ObjectFormat, []byte("same length blob")).String()) assert.Equal(t, "df0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", ComputeBlobHash(Sha256ObjectFormat, []byte("some random blob")).String()) } + +func TestIsEmptyCommitID(t *testing.T) { + assert.True(t, IsEmptyCommitID("", nil)) + assert.True(t, IsEmptyCommitID("", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("79ee38a6416c1ede423ec7ee0a8639ceea4aad20", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", nil)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha1ObjectFormat)) + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("00000000000000000000000000000000000000000", nil)) + + assert.False(t, IsEmptyCommitID("0f0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", nil)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", nil)) + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("1", nil)) + assert.False(t, IsEmptyCommitID("0", nil)) + + assert.False(t, IsEmptyCommitID("010", nil)) + assert.False(t, IsEmptyCommitID("0 0", nil)) +} diff --git a/modules/repository/push.go b/modules/repository/push.go index 751ee83a09..66d0417caf 100644 --- a/modules/repository/push.go +++ b/modules/repository/push.go @@ -21,14 +21,12 @@ type PushUpdateOptions struct { // IsNewRef return true if it's a first-time push to a branch, tag or etc. func (opts *PushUpdateOptions) IsNewRef() bool { - commitID, err := git.NewIDFromString(opts.OldCommitID) - return err == nil && commitID.IsZero() + return git.IsEmptyCommitID(opts.OldCommitID, nil) } // IsDelRef return true if it's a deletion to a branch or tag func (opts *PushUpdateOptions) IsDelRef() bool { - commitID, err := git.NewIDFromString(opts.NewCommitID) - return err == nil && commitID.IsZero() + return git.IsEmptyCommitID(opts.NewCommitID, nil) } // IsUpdateRef return true if it's an update operation diff --git a/package-lock.json b/package-lock.json index b6b4913a1d..5e9a74dd38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "jquery": "3.7.1", "katex": "0.16.10", "license-checker-webpack-plugin": "0.2.1", - "mermaid": "10.9.0", + "mermaid": "10.9.1", "mini-css-extract-plugin": "2.9.0", "minimatch": "9.0.4", "monaco-editor": "0.47.0", @@ -8412,9 +8412,9 @@ } }, "node_modules/mermaid": { - "version": "10.9.0", - "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.9.0.tgz", - "integrity": "sha512-swZju0hFox/B/qoLKK0rOxxgh8Cf7rJSfAUc1u8fezVihYMvrJAS45GzAxTVf4Q+xn9uMgitBcmWk7nWGXOs/g==", + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.9.1.tgz", + "integrity": "sha512-Mx45Obds5W1UkW1nv/7dHRsbfMM1aOKA2+Pxs/IGHNonygDHwmng8xTHyS9z4KWVi0rbko8gjiBmuwwXQ7tiNA==", "dependencies": { "@braintree/sanitize-url": "^6.0.1", "@types/d3-scale": "^4.0.3", diff --git a/package.json b/package.json index 733eb7878d..1aeecee612 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "jquery": "3.7.1", "katex": "0.16.10", "license-checker-webpack-plugin": "0.2.1", - "mermaid": "10.9.0", + "mermaid": "10.9.1", "mini-css-extract-plugin": "2.9.0", "minimatch": "9.0.4", "monaco-editor": "0.47.0", diff --git a/release-notes/8.0.0/fix/3776.md b/release-notes/8.0.0/fix/3776.md new file mode 100644 index 0000000000..b3577271e8 --- /dev/null +++ b/release-notes/8.0.0/fix/3776.md @@ -0,0 +1 @@ +- backticks in [mermaid](https://mermaid.js.org/) block diagram labels [are not sanitized properly](https://github.com/mermaid-js/mermaid/commit/c7fe9a646574597adefe3e6fb2b3707112a151aa) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 10b300f3df..b78f19d51e 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -239,7 +239,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } // If we've pushed a branch (and not deleted it) - if !git.IsEmptyCommitID(newCommitID) && refFullName.IsBranch() { + if !git.IsEmptyCommitID(newCommitID, nil) && refFullName.IsBranch() { // First ensure we have the repository loaded, we're allowed pulls requests and we can get the base repo if repo == nil { repo = loadRepository(ctx, ownerName, repoName) diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 6551da39e7..3a6dd9db5b 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -515,8 +515,7 @@ func (*actionsNotifier) MergePullRequest(ctx context.Context, doer *user_model.U } func (n *actionsNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { - commitID, _ := git.NewIDFromString(opts.NewCommitID) - if commitID.IsZero() { + if git.IsEmptyCommitID(opts.NewCommitID, nil) { log.Trace("new commitID is empty") return } diff --git a/templates/install.tmpl b/templates/install.tmpl index d49de33a3f..682e1e6511 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -174,7 +174,7 @@