loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor markup code (#31399)

1. use clearer names
2. remove deadcode
3. avoid name shadowing
4. eliminate some lint warnings

(cherry picked from commit 5a7376c0605415e63cb5b3b8f89ead01e567229b)

Conflicts:
modules/markup/html.go
simple code divergence, trivial logic

authored by

wxiaoguang and committed by
Earl Warren
75bbca68 9c48511c

+6 -31
-1
.deadcode-out
··· 210 210 StdJSON.Indent 211 211 212 212 code.gitea.io/gitea/modules/markup 213 - IsSameDomain 214 213 GetRendererByType 215 214 RenderString 216 215 IsMarkupFile
+6 -19
modules/markup/html.go
··· 143 143 common.LinkRegex, _ = xurls.StrictMatchingScheme(strings.Join(withAuth, "|")) 144 144 } 145 145 146 - // IsSameDomain checks if given url string has the same hostname as current Gitea instance 147 - func IsSameDomain(s string) bool { 148 - if strings.HasPrefix(s, "/") { 149 - return true 150 - } 151 - if uapp, err := url.Parse(setting.AppURL); err == nil { 152 - if u, err := url.Parse(s); err == nil { 153 - return u.Host == uapp.Host 154 - } 155 - return false 156 - } 157 - return false 158 - } 159 - 160 146 type postProcessError struct { 161 147 context string 162 148 err error ··· 393 379 // We ignore code and pre. 394 380 switch node.Type { 395 381 case html.TextNode: 396 - textNode(ctx, procs, node) 382 + processTextNodes(ctx, procs, node) 397 383 case html.ElementNode: 398 384 if node.Data == "img" { 399 385 for i, attr := range node.Attr { ··· 436 422 for n := node.FirstChild; n != nil; n = n.NextSibling { 437 423 visitNode(ctx, procs, n) 438 424 } 425 + default: 439 426 } 440 427 // ignore everything else 441 428 } 442 429 443 - // textNode runs the passed node through various processors, in order to handle 430 + // processTextNodes runs the passed node through various processors, in order to handle 444 431 // all kinds of special links handled by the post-processing. 445 - func textNode(ctx *RenderContext, procs []processor, node *html.Node) { 446 - for _, processor := range procs { 447 - processor(ctx, node) 432 + func processTextNodes(ctx *RenderContext, procs []processor, node *html.Node) { 433 + for _, p := range procs { 434 + p(ctx, node) 448 435 } 449 436 } 450 437
-11
modules/markup/html_test.go
··· 135 135 `<p><a href="`+urlWithQuery+`" rel="nofollow"><code>`+sha[:10]+`/README.md (L1-L5)</code></a></p>`) 136 136 } 137 137 138 - func TestMisc_IsSameDomain(t *testing.T) { 139 - setting.AppURL = markup.TestAppURL 140 - 141 - sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579" 142 - commit := util.URLJoin(markup.TestRepoURL, "commit", sha) 143 - 144 - assert.True(t, markup.IsSameDomain(commit)) 145 - assert.False(t, markup.IsSameDomain("http://google.com/ncr")) 146 - assert.False(t, markup.IsSameDomain("favicon.ico")) 147 - } 148 - 149 138 func TestRender_links(t *testing.T) { 150 139 setting.AppURL = markup.TestAppURL 151 140