修复bug
This commit is contained in:
parent
2f456f62c0
commit
01e10f69dd
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/dlclark/regexp2"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
strings2 "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"html/template"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -95,7 +96,7 @@ func StripTags(str, allowable string) string {
|
||||
return html
|
||||
}
|
||||
|
||||
var tag = regexp.MustCompile(`<(.*?)>`)
|
||||
var tag = regexp.MustCompile(`(?is:<(.*?)>)`) //使用忽略大小写和包含换行符模式
|
||||
|
||||
func StripTagsX(str, allowable string) string {
|
||||
if allowable == "" {
|
||||
@ -119,7 +120,6 @@ func StripTagsX(str, allowable string) string {
|
||||
return html
|
||||
}
|
||||
|
||||
var tagx = regexp.MustCompile(`(</?[a-z0-9]+?)( |>)`)
|
||||
var selfCloseTags = map[string]string{"area": "", "base": "", "basefont": "", "br": "", "col": "", "command": "", "fecolormatrix": "", "embed": "", "frame": "", "hr": "", "img": "", "input": "", "isindex": "", "link": "", "fecomposite": "", "fefuncr": "", "fefuncg": "", "fefuncb": "", "fefunca": "", "meta": "", "param": "", "!doctype": "", "source": "", "track": "", "wbr": ""}
|
||||
|
||||
func CloseTag(str string) string {
|
||||
@ -130,7 +130,11 @@ func CloseTag(str string) string {
|
||||
var tagss = make([]string, 0, len(tags))
|
||||
for _, s := range tags {
|
||||
ss := strings.Split(s, " ")
|
||||
sss := strings.ReplaceAll(ss[0], "\\", "")
|
||||
sss := strings2.Replace(ss[0], map[string]string{
|
||||
"\\": "",
|
||||
"\n": "",
|
||||
"\\/": "/",
|
||||
})
|
||||
if strings.Contains(sss, "<!") {
|
||||
continue
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package html
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@ -182,22 +181,6 @@ func TestCloseHtmlTag(t *testing.T) {
|
||||
args: args{str: `<pre><div>`},
|
||||
want: "</div></pre>",
|
||||
},
|
||||
{
|
||||
name: "t3",
|
||||
args: args{str: func() string {
|
||||
s, err := os.ReadFile("/home/xing/aaa.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(s)
|
||||
}()},
|
||||
want: "</div></pre>",
|
||||
},
|
||||
{
|
||||
name: "t5",
|
||||
args: args{str: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0" focusable="false" role="none" style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;"><defs><filter id="wp-duotone-dark-grayscale"><feColorMatrix color-interpolation-filters="sRGB" type="matrix" values=" .299 .587 .114 0 0 .299 .587 .114 0 0 .299 .587 .114 0 0 .299 .587 .114 0 0 "></feColorMatrix><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="table" tableValues="0 0.49803921568627"></feFuncR><feFuncG type="table" tableValues="0 0.49803921568627"></feFuncG><feFuncB type="table" tableValues="0 0.49803921568627"></feFuncB><feFuncA type="table" tableValues="1 1"></feFuncA></feComponentTransfer><feComposite in2="SourceGraphic" operator="in"></feComposite></filter></defs></svg>`},
|
||||
want: "</div></pre>",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -48,9 +48,10 @@
|
||||
<nav aria-label="分类">
|
||||
<ul>
|
||||
{{range $k,$v := .categories}}
|
||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}"><a
|
||||
href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||
{{end}}
|
||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}">
|
||||
<a href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
@ -54,9 +54,10 @@
|
||||
<nav aria-label="分类">
|
||||
<ul>
|
||||
{{range $k,$v := .categories}}
|
||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}"><a
|
||||
href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||
{{end}}
|
||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}">
|
||||
<a href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
Loading…
Reference in New Issue
Block a user