Change order that PostProcess Processors are run (#6445)
Make sure Processors that work on full links are run first so that something matching another pattern doesn't alter a link before we get to it, for example: https://stackoverflow.com/questions/2896191/what-is-go-used-fore Fixes #4813
This commit is contained in:
parent
d77176912b
commit
c8650aef0a
2 changed files with 13 additions and 7 deletions
|
@ -152,15 +152,15 @@ func (p *postProcessError) Error() string {
|
||||||
type processor func(ctx *postProcessCtx, node *html.Node)
|
type processor func(ctx *postProcessCtx, node *html.Node)
|
||||||
|
|
||||||
var defaultProcessors = []processor{
|
var defaultProcessors = []processor{
|
||||||
mentionProcessor,
|
|
||||||
shortLinkProcessor,
|
|
||||||
fullIssuePatternProcessor,
|
fullIssuePatternProcessor,
|
||||||
|
fullSha1PatternProcessor,
|
||||||
|
shortLinkProcessor,
|
||||||
|
linkProcessor,
|
||||||
|
mentionProcessor,
|
||||||
issueIndexPatternProcessor,
|
issueIndexPatternProcessor,
|
||||||
crossReferenceIssueIndexPatternProcessor,
|
crossReferenceIssueIndexPatternProcessor,
|
||||||
fullSha1PatternProcessor,
|
|
||||||
sha1CurrentPatternProcessor,
|
sha1CurrentPatternProcessor,
|
||||||
emailAddressProcessor,
|
emailAddressProcessor,
|
||||||
linkProcessor,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type postProcessCtx struct {
|
type postProcessCtx struct {
|
||||||
|
@ -194,14 +194,14 @@ func PostProcess(
|
||||||
}
|
}
|
||||||
|
|
||||||
var commitMessageProcessors = []processor{
|
var commitMessageProcessors = []processor{
|
||||||
mentionProcessor,
|
|
||||||
fullIssuePatternProcessor,
|
fullIssuePatternProcessor,
|
||||||
|
fullSha1PatternProcessor,
|
||||||
|
linkProcessor,
|
||||||
|
mentionProcessor,
|
||||||
issueIndexPatternProcessor,
|
issueIndexPatternProcessor,
|
||||||
crossReferenceIssueIndexPatternProcessor,
|
crossReferenceIssueIndexPatternProcessor,
|
||||||
fullSha1PatternProcessor,
|
|
||||||
sha1CurrentPatternProcessor,
|
sha1CurrentPatternProcessor,
|
||||||
emailAddressProcessor,
|
emailAddressProcessor,
|
||||||
linkProcessor,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderCommitMessage will use the same logic as PostProcess, but will disable
|
// RenderCommitMessage will use the same logic as PostProcess, but will disable
|
||||||
|
|
|
@ -113,6 +113,12 @@ func TestRender_links(t *testing.T) {
|
||||||
test(
|
test(
|
||||||
"https://foo_bar.example.com/",
|
"https://foo_bar.example.com/",
|
||||||
`<p><a href="https://foo_bar.example.com/" rel="nofollow">https://foo_bar.example.com/</a></p>`)
|
`<p><a href="https://foo_bar.example.com/" rel="nofollow">https://foo_bar.example.com/</a></p>`)
|
||||||
|
test(
|
||||||
|
"https://stackoverflow.com/questions/2896191/what-is-go-used-fore",
|
||||||
|
`<p><a href="https://stackoverflow.com/questions/2896191/what-is-go-used-fore" rel="nofollow">https://stackoverflow.com/questions/2896191/what-is-go-used-fore</a></p>`)
|
||||||
|
test(
|
||||||
|
"https://username:password@gitea.com",
|
||||||
|
`<p><a href="https://username:password@gitea.com" rel="nofollow">https://username:password@gitea.com</a></p>`)
|
||||||
|
|
||||||
// Test that should *not* be turned into URL
|
// Test that should *not* be turned into URL
|
||||||
test(
|
test(
|
||||||
|
|
Reference in a new issue