From 923dc4309a8bfb162c6f510a1a8fa02f1dc11da3 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Wed, 27 Mar 2019 11:18:04 -0400 Subject: [PATCH 1/2] Change order that PostProcess Processors are run 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 --- modules/markup/html.go | 14 +++++++------- modules/markup/html_test.go | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index f4c5d97480b5a..e016b67d0cf39 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -152,15 +152,15 @@ func (p *postProcessError) Error() string { type processor func(ctx *postProcessCtx, node *html.Node) var defaultProcessors = []processor{ - mentionProcessor, - shortLinkProcessor, fullIssuePatternProcessor, + fullSha1PatternProcessor, + shortLinkProcessor, + linkProcessor, + mentionProcessor, issueIndexPatternProcessor, crossReferenceIssueIndexPatternProcessor, - fullSha1PatternProcessor, sha1CurrentPatternProcessor, emailAddressProcessor, - linkProcessor, } type postProcessCtx struct { @@ -194,14 +194,14 @@ func PostProcess( } var commitMessageProcessors = []processor{ - mentionProcessor, fullIssuePatternProcessor, + fullSha1PatternProcessor, + linkProcessor, + mentionProcessor, issueIndexPatternProcessor, crossReferenceIssueIndexPatternProcessor, - fullSha1PatternProcessor, sha1CurrentPatternProcessor, emailAddressProcessor, - linkProcessor, } // RenderCommitMessage will use the same logic as PostProcess, but will disable diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index ff682019959d4..b89a85b1e72d8 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -113,6 +113,13 @@ func TestRender_links(t *testing.T) { test( "https://foo_bar.example.com/", `

https://foo_bar.example.com/

`) + test( + "https://stackoverflow.com/questions/2896191/what-is-go-used-fore", + `

https://stackoverflow.com/questions/2896191/what-is-go-used-fore

`) + test( + "https://username:password@gitea.com", + `

https://username:password@gitea.com

`) + // Test that should *not* be turned into URL test( From dfaed2b78e66cc7af637749301e462aa9e78dc42 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Wed, 27 Mar 2019 11:24:41 -0400 Subject: [PATCH 2/2] fix formatting --- modules/markup/html_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index b89a85b1e72d8..8d113b18a1152 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -120,7 +120,6 @@ func TestRender_links(t *testing.T) { "https://username:password@gitea.com", `

https://username:password@gitea.com

`) - // Test that should *not* be turned into URL test( "www.example.com",