From 4b89e0a43a13667a38ec0d53affcb0e44d22cdb8 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 3 Aug 2020 16:40:05 -0400 Subject: [PATCH] move emuxifier into html filter to avoid link damage --- docs/changelog.txt | 2 ++ fun.go | 57 +++++++++++++++++++--------------------------- go.mod | 2 +- go.sum | 6 ++--- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index a2336d9..7fc6c7a 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog === next ++ Reduce interference between various text substitution rules. + + Fix crash in search with extra space. + Fix pubkey issue with domain only keys. diff --git a/fun.go b/fun.go index 30c8111..92a523e 100644 --- a/fun.go +++ b/fun.go @@ -97,6 +97,29 @@ func reverbolate(userid int64, honks []*Honk) { htf.Imager = replaceimgsand(zap, false) htf.SpanClasses = allowedclasses htf.BaseURL, _ = url.Parse(h.XID) + emuxifier := func(e string) string { + for _, d := range h.Donks { + if d.Name == e { + zap[d.XID] = true + if d.Local { + return fmt.Sprintf(``, d.Name, d.XID) + } + } + } + if local && h.What != "bonked" { + var emu Emu + emucache.Get(e, &emu) + if emu.ID != "" { + return fmt.Sprintf(``, emu.Name, emu.ID) + } + } + return e + } + htf.FilterText = func(w io.Writer, data string) { + data = htfilter.EscapeText(data) + data = re_emus.ReplaceAllStringFunc(data, emuxifier) + io.WriteString(w, data) + } p, _ := htf.String(h.Precis) n, _ := htf.String(h.Noise) h.Precis = string(p) @@ -115,41 +138,7 @@ func reverbolate(userid int64, honks []*Honk) { unsee(honks, userid) for _, h := range honks { - local := false - if h.Whofore == 2 || h.Whofore == 3 { - local = true - } - zap := make(map[string]bool) - emuxifier := func(e string) string { - for _, d := range h.Donks { - if d.Name == e { - zap[d.XID] = true - if d.Local { - return fmt.Sprintf(``, d.Name, d.XID) - } - } - } - if local && h.What != "bonked" { - var emu Emu - emucache.Get(e, &emu) - if emu.ID != "" { - return fmt.Sprintf(``, emu.Name, emu.ID) - } - } - return e - } renderflags(h) - h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier) - h.Noise = re_emus.ReplaceAllStringFunc(h.Noise, emuxifier) - - j := 0 - for i := 0; i < len(h.Donks); i++ { - if !zap[h.Donks[i].XID] { - h.Donks[j] = h.Donks[i] - j++ - } - } - h.Donks = h.Donks[:j] h.HTPrecis = template.HTML(h.Precis) h.HTML = template.HTML(h.Noise) diff --git a/go.mod b/go.mod index 15a49be..ea00ed9 100644 --- a/go.mod +++ b/go.mod @@ -9,5 +9,5 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.42 + humungus.tedunangst.com/r/webs v0.6.43 ) diff --git a/go.sum b/go.sum index c8467b6..4a87d31 100644 --- a/go.sum +++ b/go.sum @@ -22,7 +22,5 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.41 h1:kteIzz03ij7EujsLLbRlquSgONRzoqIm1o1Bc5ie6HU= -humungus.tedunangst.com/r/webs v0.6.41/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= -humungus.tedunangst.com/r/webs v0.6.42 h1:y1j7Z04Bs8/UmzYwsQb2OfOs1F1veJ6u9bwjc70PhLo= -humungus.tedunangst.com/r/webs v0.6.42/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.43 h1:V7tmvzXi/LETO2QfHyqvIivi1kbjRSHQoDFcR3hML+k= +humungus.tedunangst.com/r/webs v0.6.43/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=