1
1
package xss
2
2
3
3
import (
4
+ "fmt"
4
5
"strconv"
5
6
"strings"
6
- "fmt"
7
7
)
8
8
9
9
type XssOption struct {
@@ -41,13 +41,13 @@ type TagOption struct {
41
41
IsWhite bool
42
42
}
43
43
44
- //NewXssOption
44
+ // NewXssOption
45
45
func NewXssOption () XssOption {
46
46
option := XssOption {}
47
47
return option
48
48
}
49
49
50
- //NewDefaultXssOption
50
+ // NewDefaultXssOption
51
51
func NewDefaultXssOption () XssOption {
52
52
53
53
defaultOption := XssOption {}
@@ -70,7 +70,7 @@ type StripTagBodyResult struct {
70
70
Remove func (html string ) string
71
71
}
72
72
73
- //GetDefaultWhiteList 默认白名单
73
+ // GetDefaultWhiteList 默认白名单
74
74
func GetDefaultWhiteList () map [string ][]string {
75
75
76
76
result := map [string ][]string {
@@ -113,6 +113,7 @@ func GetDefaultWhiteList() map[string][]string {
113
113
"i" : {},
114
114
"img" : {"src" , "alt" , "title" , "width" , "height" },
115
115
"ins" : {"datetime" },
116
+ "kbd" : {},
116
117
"li" : {},
117
118
"mark" : {},
118
119
"nav" : {},
@@ -311,7 +312,7 @@ func safeAttrValue(tag, name, value string) string {
311
312
return value
312
313
}
313
314
314
- //FriendlyAttrValue get friendly attribute value
315
+ // FriendlyAttrValue get friendly attribute value
315
316
func FriendlyAttrValue (str string ) string {
316
317
str = unescapeQuote (str )
317
318
str = escapeHTMLEntities (str )
@@ -320,12 +321,12 @@ func FriendlyAttrValue(str string) string {
320
321
return str
321
322
}
322
323
323
- //unescapeQuote unescape double quote
324
+ // unescapeQuote unescape double quote
324
325
func unescapeQuote (str string ) string {
325
326
return regQuote2 .ReplaceAllString (str , "\" " )
326
327
}
327
328
328
- //escapeHtmlEntities
329
+ // escapeHtmlEntities
329
330
func escapeHTMLEntities (str string ) string {
330
331
return regAttrValue1 .ReplaceAllStringFunc (str , func (input string ) string {
331
332
input = input [2 :]
@@ -338,26 +339,26 @@ func escapeHTMLEntities(str string) string {
338
339
339
340
i , err := strconv .ParseInt (input [1 :], 16 , 32 )
340
341
if err == nil {
341
- return fmt .Sprintf ("%c" ,i )
342
+ return fmt .Sprintf ("%c" , i )
342
343
}
343
344
return ""
344
345
345
346
}
346
347
i , err := strconv .Atoi (input )
347
348
if err == nil {
348
- return fmt .Sprintf ("%c" ,i )
349
+ return fmt .Sprintf ("%c" , i )
349
350
}
350
351
351
352
return ""
352
353
})
353
354
}
354
355
355
- //escapeDangerHTML5Entities
356
+ // escapeDangerHTML5Entities
356
357
func escapeDangerHTML5Entities (str string ) string {
357
358
return regAttrNewLine .ReplaceAllString (regAttrValueColon .ReplaceAllString (str , ":" ), " " )
358
359
}
359
360
360
- //clearNonPrintableCharacter
361
+ // clearNonPrintableCharacter
361
362
func clearNonPrintableCharacter (str string ) string {
362
363
363
364
var b strings.Builder
@@ -378,7 +379,7 @@ func escapeQuote(str string) string {
378
379
return regQuote .ReplaceAllString (str , """ )
379
380
}
380
381
381
- //escapeHTML
382
+ // escapeHTML
382
383
func escapeHTML (html string ) string {
383
384
384
385
// return regGT.ReplaceAllString(regLT.ReplaceAllString(html, "<"), ">")
0 commit comments