Skip to content

Commit 4a0f7c1

Browse files
mrsdizzietechknowlogick
authored andcommitted
Change order that PostProcess Processors are run (#6445) (#6447)
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
1 parent e54f7a7 commit 4a0f7c1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

modules/markup/html.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ func (p *postProcessError) Error() string {
152152
type processor func(ctx *postProcessCtx, node *html.Node)
153153

154154
var defaultProcessors = []processor{
155-
mentionProcessor,
156-
shortLinkProcessor,
157155
fullIssuePatternProcessor,
156+
fullSha1PatternProcessor,
157+
shortLinkProcessor,
158+
linkProcessor,
159+
mentionProcessor,
158160
issueIndexPatternProcessor,
159161
crossReferenceIssueIndexPatternProcessor,
160-
fullSha1PatternProcessor,
161162
sha1CurrentPatternProcessor,
162163
emailAddressProcessor,
163-
linkProcessor,
164164
}
165165

166166
type postProcessCtx struct {
@@ -194,14 +194,14 @@ func PostProcess(
194194
}
195195

196196
var commitMessageProcessors = []processor{
197-
mentionProcessor,
198197
fullIssuePatternProcessor,
198+
fullSha1PatternProcessor,
199+
linkProcessor,
200+
mentionProcessor,
199201
issueIndexPatternProcessor,
200202
crossReferenceIssueIndexPatternProcessor,
201-
fullSha1PatternProcessor,
202203
sha1CurrentPatternProcessor,
203204
emailAddressProcessor,
204-
linkProcessor,
205205
}
206206

207207
// RenderCommitMessage will use the same logic as PostProcess, but will disable

modules/markup/html_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ func TestRender_links(t *testing.T) {
113113
test(
114114
"https://foo_bar.example.com/",
115115
`<p><a href="https://foo_bar.example.com/" rel="nofollow">https://foo_bar.example.com/</a></p>`)
116+
test(
117+
"https://stackoverflow.com/questions/2896191/what-is-go-used-fore",
118+
`<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>`)
119+
test(
120+
"https://username:[email protected]",
121+
`<p><a href="https://username:[email protected]" rel="nofollow">https://username:[email protected]</a></p>`)
116122

117123
// Test that should *not* be turned into URL
118124
test(

0 commit comments

Comments
 (0)