File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ type AttrResult struct {
6262 Closing bool
6363}
6464
65+ // GetAttrs 获取标签属性
6566func GetAttrs (html string ) AttrResult {
6667 i := spaceIndex (html )
6768 if i == - 1 {
@@ -72,7 +73,10 @@ func GetAttrs(html string) AttrResult {
7273 }
7374 html = strings .TrimSpace (html [i + 1 : len (html )- 1 ])
7475
75- isClosing := html [len (html )- 1 ] == '/'
76+ var isClosing = false
77+ if len (html ) > 0 {
78+ isClosing = html [len (html )- 1 ] == '/'
79+ }
7680
7781 if isClosing {
7882 html = strings .TrimSpace (html [0 : len (html )- 1 ])
Original file line number Diff line number Diff line change @@ -1329,6 +1329,17 @@ func TestOnIgnoreTagAttr(t *testing.T) {
13291329 }
13301330}
13311331
1332+ // TestOnIgnoreWhiteListTagNullAttr 测试忽略tag 空属性
1333+ func TestOnIgnoreWhiteListTagNullAttr (t * testing.T ) {
1334+ source := "<a >bb</a>"
1335+
1336+ html := FilterXSS (source , XssOption {WhiteList : GetDefaultWhiteList ()})
1337+
1338+ if html != "<a>bb</a>" {
1339+ t .Errorf ("TestOnIgnoreWhiteListTagNullAttr error" )
1340+ }
1341+ }
1342+
13321343func TestOnIgnoreTagAttrWithReturn (t * testing.T ) {
13331344 source := "<a href=\" #\" target=\" _blank\" checked data-a=\" b\" >hi</a href=\" d\" >"
13341345
You can’t perform that action at this time.
0 commit comments