mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
Some checks are pending
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / Check go fix (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres (shard 0) (push) Blocked by required conditions
Server CI / Postgres (shard 1) (push) Blocked by required conditions
Server CI / Postgres (shard 2) (push) Blocked by required conditions
Server CI / Postgres (shard 3) (push) Blocked by required conditions
Server CI / Merge Postgres Test Results (push) Blocked by required conditions
Server CI / Elasticsearch v8 Compatibility (push) Blocked by required conditions
Server CI / Postgres FIPS (shard 0) (push) Blocked by required conditions
Server CI / Postgres FIPS (shard 1) (push) Blocked by required conditions
Server CI / Postgres FIPS (shard 2) (push) Blocked by required conditions
Server CI / Postgres FIPS (shard 3) (push) Blocked by required conditions
Server CI / Merge Postgres FIPS Test Results (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Tools CI / check-style (mattermost-govet) (push) Waiting to run
Tools CI / Test (mattermost-govet) (push) Waiting to run
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Blocked by required conditions
Web App CI / check-external-links (push) Blocked by required conditions
Web App CI / check-types (push) Blocked by required conditions
Web App CI / test (platform) (push) Blocked by required conditions
Web App CI / test (mattermost-redux) (push) Blocked by required conditions
Web App CI / test (channels shard 1/4) (push) Blocked by required conditions
Web App CI / test (channels shard 2/4) (push) Blocked by required conditions
Web App CI / test (channels shard 3/4) (push) Blocked by required conditions
Web App CI / test (channels shard 4/4) (push) Blocked by required conditions
Web App CI / upload-coverage (push) Blocked by required conditions
Web App CI / build (push) Blocked by required conditions
YAML Lint / yamllint (push) Waiting to run
* Simplify invite_people email parsing Replace backwards in-place mutation loop with a straightforward forward filter into a new slice. Extract into parseEmailList so the logic can be unit tested directly. * MM-68150: Upgrade golangci-lint to v2.12.2 Remove //go:fix inline from NewPointer, which is a generic function not yet supported by the inline analyzer, and fix 11 slicesbackward modernize issues flagged by the new version. * MM-68150: Enable all linters by default; disable those with >20 existing issues Switch from opt-in (default: none) to opt-out (default: all) so new linters added to golangci-lint are evaluated automatically. Explicitly disable every linter that has more than 20 pre-existing violations, deferring those for later cleanup. Also disable a handful of linters whose violations are intentional patterns in this codebase (nilerr, dogsled, sqlclosecheck, iotamixing, predeclared, containedctx, iface, gocheckcompilerdirectives, promlinter, goprintffuncname, gomoddirectives). * MM-68150: Fix mirror linter issues Replace Write([]byte(s)) with WriteString(s), and FindIndex([]byte(s)) with FindStringIndex(s), to avoid unnecessary allocations. * MM-68150: Fix nosprintfhostport linter issue Use net.JoinHostPort to construct host:port strings instead of fmt.Sprintf with a manually formatted pattern. * MM-68150: Fix rowserrcheck and sqlclosecheck linter issues Check rows.Err() after iteration loops in schema_dump.go. In the sqlx_wrapper test, defer rows.Close() rather than closing inline. * MM-68150: Fix nilnesserr linter issues — wrong variable in error handlers In 11 places, a stale variable (often the outer err from a prior assignment) was used instead of the freshly-checked error variable (appErr, rowErr, jsonErr, writeErr, esErr). Each produces a typed-nil wrapped in a non-nil interface, silently discarding the real error. * MM-68150: Add i18n string for app.compile_csv_chunks.write_error --------- Co-authored-by: Mattermost Build <build@mattermost.com>
125 lines
3.1 KiB
Go
125 lines
3.1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package markdown
|
|
|
|
import "slices"
|
|
|
|
const (
|
|
// Assuming 64k maxSize of a post which can be stored in DB.
|
|
// Allow scanning upto twice(arbitrary value) the post size.
|
|
maxLen = 1024 * 64 * 2
|
|
)
|
|
|
|
// Inspect traverses the markdown tree in depth-first order. If f returns true, Inspect invokes f
|
|
// recursively for each child of the block or inline, followed by a call of f(nil).
|
|
func Inspect(markdown string, f func(any) bool) {
|
|
if len(markdown) > maxLen {
|
|
return
|
|
}
|
|
document, referenceDefinitions := Parse(markdown)
|
|
InspectBlock(document, func(block Block) bool {
|
|
if !f(block) {
|
|
return false
|
|
}
|
|
switch v := block.(type) {
|
|
case *Paragraph:
|
|
for _, inline := range MergeInlineText(v.ParseInlines(referenceDefinitions)) {
|
|
InspectInline(inline, func(inline Inline) bool {
|
|
return f(inline)
|
|
})
|
|
}
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
|
|
// InspectBlock traverses the blocks in depth-first order, starting with block. If f returns true,
|
|
// InspectBlock invokes f recursively for each child of the block, followed by a call of f(nil).
|
|
func InspectBlock(block Block, f func(Block) bool) {
|
|
stack := []Block{block}
|
|
// Using seen for backtracking
|
|
seen := map[Block]bool{}
|
|
|
|
for len(stack) > 0 {
|
|
// "peek" the node from the stack
|
|
block := stack[len(stack)-1]
|
|
|
|
if seen[block] {
|
|
// "pop" the node only when backtracking(seen)
|
|
stack = stack[:len(stack)-1]
|
|
f(nil)
|
|
continue
|
|
}
|
|
seen[block] = true
|
|
|
|
// Process the node
|
|
if !f(block) {
|
|
continue
|
|
}
|
|
|
|
switch v := block.(type) {
|
|
case *Document:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *List:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *ListItem:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *BlockQuote:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// InspectInline traverses the blocks in depth-first order, starting with block. If f returns true,
|
|
// InspectInline invokes f recursively for each child of the block, followed by a call of f(nil).
|
|
func InspectInline(inline Inline, f func(Inline) bool) {
|
|
stack := []Inline{inline}
|
|
// Using seen for backtracking
|
|
seen := map[Inline]bool{}
|
|
|
|
for len(stack) > 0 {
|
|
// "peek" the node from the stack
|
|
inline := stack[len(stack)-1]
|
|
|
|
if seen[inline] {
|
|
// "pop" the node only when backtracking(seen)
|
|
stack = stack[:len(stack)-1]
|
|
f(nil)
|
|
continue
|
|
}
|
|
seen[inline] = true
|
|
|
|
// Process the node
|
|
if !f(inline) {
|
|
continue
|
|
}
|
|
|
|
switch v := inline.(type) {
|
|
case *InlineImage:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *InlineLink:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *ReferenceImage:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
case *ReferenceLink:
|
|
for _, v0 := range slices.Backward(v.Children) {
|
|
stack = append(stack, v0)
|
|
}
|
|
}
|
|
}
|
|
}
|