From 01e10f69dd40933041227a0018232587761b5f04 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 5 Mar 2023 21:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/html/html.go | 10 +++++++--- helper/html/html_test.go | 17 ----------------- .../theme/twentyfifteen/layout/sidebar.gohtml | 7 ++++--- .../theme/twentyseventeen/layout/sidebar.gohtml | 7 ++++--- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/helper/html/html.go b/helper/html/html.go index 313578e..2131799 100644 --- a/helper/html/html.go +++ b/helper/html/html.go @@ -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(`()`) 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, "
`}, want: "
", }, - { - name: "t3", - args: args{str: func() string { - s, err := os.ReadFile("/home/xing/aaa.html") - if err != nil { - panic(err) - } - return string(s) - }()}, - want: "", - }, - { - name: "t5", - args: args{str: ``}, - want: "", - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/theme/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml index 1d77a23..e614563 100644 --- a/internal/theme/twentyfifteen/layout/sidebar.gohtml +++ b/internal/theme/twentyfifteen/layout/sidebar.gohtml @@ -48,9 +48,10 @@ diff --git a/internal/theme/twentyseventeen/layout/sidebar.gohtml b/internal/theme/twentyseventeen/layout/sidebar.gohtml index 05800ab..59c7acd 100644 --- a/internal/theme/twentyseventeen/layout/sidebar.gohtml +++ b/internal/theme/twentyseventeen/layout/sidebar.gohtml @@ -54,9 +54,10 @@