Files
T Mohan Adityaandsilverwind c6bdd3efd6 fix(markup): continue scanning text nodes after skipped matches (#40506)
Several markup processors stopped scanning a text node after skipping
one match. An external issue or code preview URL hid later local ones,
an SSH remote like `git@host:org/repo.git` hid a later email address, a
short link with a disallowed scheme hid later short links, and a text
node ending in an ellipsis left all its URLs unlinked.

The processors now continue past skipped matches. Only a URL in the last
word of a text node ending in an ellipsis is treated as truncated.

Fixes: https://github.com/go-gitea/gitea/issues/40505

Assisted-by: OpenCode:gemini-4-neon
Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: silverwind <me@silverwind.io>
2026-11-27 05:42:42 +00:00

24 lines
696 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package markup
import (
"strings"
"testing"
"gitea.dev/modules/test"
"github.com/stretchr/testify/assert"
)
func TestShortLinkProcessor(t *testing.T) {
test := func(input, expected string) {
sb := new(strings.Builder)
err := postProcess(NewTestRenderContext("/base"), []processor{shortLinkProcessor}, strings.NewReader(input), sb)
assert.NoError(t, err)
assert.Equal(t, test.NormalizeHTMLSpaces(expected), test.NormalizeHTMLSpaces(sb.String()))
}
test("[[name=foo|link=javascript:bar]] and [[name=ok|link=./link]]", `[[name=foo|link=javascript:bar]] and <a href="/base/link">ok</a>`)
}