33 lignes
923 o
Go
33 lignes
923 o
Go
|
package sanitize
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestSafe(t *testing.T) {
|
||
|
safeString := map[string]string{
|
||
|
"'": "'",
|
||
|
"&": "&",
|
||
|
"http://exemple.com": "http://exemple.com",
|
||
|
}
|
||
|
for key, val := range safeString {
|
||
|
safe := Safe(key)
|
||
|
if string(safe) != val {
|
||
|
t.Errorf("Safe doesn't escape the right values, expected result %s, got %s", key, val)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestSafeText(t *testing.T) {
|
||
|
safeString := map[string]string{
|
||
|
"'": "'",
|
||
|
"&": "&",
|
||
|
"http://exemple.com": "http://exemple.com",
|
||
|
"<em>test</em><script>lol();</script>": "<em>test</em><script>lol();</script>",
|
||
|
}
|
||
|
for key, val := range safeString {
|
||
|
safe := Safe(key)
|
||
|
if string(safe) != val {
|
||
|
t.Errorf("Safe doesn't escape the right values, expected result %s, got %s", key, val)
|
||
|
}
|
||
|
}
|
||
|
}
|