修复bug
This commit is contained in:
parent
2f456f62c0
commit
01e10f69dd
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dlclark/regexp2"
|
"github.com/dlclark/regexp2"
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
|
strings2 "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
"html/template"
|
"html/template"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -95,7 +96,7 @@ func StripTags(str, allowable string) string {
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag = regexp.MustCompile(`<(.*?)>`)
|
var tag = regexp.MustCompile(`(?is:<(.*?)>)`) //使用忽略大小写和包含换行符模式
|
||||||
|
|
||||||
func StripTagsX(str, allowable string) string {
|
func StripTagsX(str, allowable string) string {
|
||||||
if allowable == "" {
|
if allowable == "" {
|
||||||
|
@ -119,7 +120,6 @@ func StripTagsX(str, allowable string) string {
|
||||||
return html
|
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": ""}
|
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 {
|
func CloseTag(str string) string {
|
||||||
|
@ -130,7 +130,11 @@ func CloseTag(str string) string {
|
||||||
var tagss = make([]string, 0, len(tags))
|
var tagss = make([]string, 0, len(tags))
|
||||||
for _, s := range tags {
|
for _, s := range tags {
|
||||||
ss := strings.Split(s, " ")
|
ss := strings.Split(s, " ")
|
||||||
sss := strings.ReplaceAll(ss[0], "\\", "")
|
sss := strings2.Replace(ss[0], map[string]string{
|
||||||
|
"\\": "",
|
||||||
|
"\n": "",
|
||||||
|
"\\/": "/",
|
||||||
|
})
|
||||||
if strings.Contains(sss, "<!") {
|
if strings.Contains(sss, "<!") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -182,22 +181,6 @@ func TestCloseHtmlTag(t *testing.T) {
|
||||||
args: args{str: `<pre><div>`},
|
args: args{str: `<pre><div>`},
|
||||||
want: "</div></pre>",
|
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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
|
@ -48,9 +48,10 @@
|
||||||
<nav aria-label="分类">
|
<nav aria-label="分类">
|
||||||
<ul>
|
<ul>
|
||||||
{{range $k,$v := .categories}}
|
{{range $k,$v := .categories}}
|
||||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}"><a
|
<li class="cat-item cat-item-{{$v.Terms.TermId}}">
|
||||||
href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
<a href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||||
{{end}}
|
</li>
|
||||||
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -54,9 +54,10 @@
|
||||||
<nav aria-label="分类">
|
<nav aria-label="分类">
|
||||||
<ul>
|
<ul>
|
||||||
{{range $k,$v := .categories}}
|
{{range $k,$v := .categories}}
|
||||||
<li class="cat-item cat-item-{{$v.Terms.TermId}}"><a
|
<li class="cat-item cat-item-{{$v.Terms.TermId}}">
|
||||||
href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
<a href="/p/category/{{$v.Name}}">{{$v.Name}}</a>
|
||||||
{{end}}
|
</li>
|
||||||
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user