-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute.go
More file actions
90 lines (73 loc) · 1.75 KB
/
attribute.go
File metadata and controls
90 lines (73 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package sanitize
type (
// Attribute represents an HTML tag's attribute.
//
// Any modifications to this structure will impact on the sanitization result.
//
// Namespace and Key are normalized by default to prevent charset attacks.
// Val is quoted when rendering the sanitized output.
Attribute struct {
namespace string
key string
value string
blocked bool
safeNamespace string
safeKey string
safeValue string
}
// AttributePolicy is an attribute supervisor. It allows or blocks tag's attributes.
// Any modifications will be propagated to the content rendering.
AttributePolicy func(a *Attribute)
)
func NewAttribute(namespace, key, value string) *Attribute {
return &Attribute{
namespace: namespace,
key: key,
value: value,
safeNamespace: Normalize(namespace),
safeKey: Normalize(key),
safeValue: Normalize(value),
}
}
func (p AttributePolicy) Apply(tag *Tag) {
tag.AttrPolicy(p)
}
func (a *Attribute) IsBlocked() bool {
return a.blocked
}
func (a *Attribute) Block() {
a.blocked = true
}
func (a *Attribute) Allow() {
a.blocked = false
}
func (a *Attribute) UnsafeKey() string {
return a.key
}
func (a *Attribute) Key() string {
return a.safeKey
}
func (a *Attribute) UnsafeValue() string {
return a.value
}
func (a *Attribute) Value() string {
return a.safeValue
}
func (a *Attribute) UnsafeNamespace() string {
return a.namespace
}
func (a *Attribute) Namespace() string {
return a.safeNamespace
}
func (a *Attribute) SetKey(value string) {
a.key = value
a.safeKey = value
}
func (a *Attribute) SetValue(value string) {
a.value = value
a.safeValue = a.value
}
func (a *Attribute) SetNamespace(value string) {
a.namespace = value
a.safeNamespace = value
}