package main
import (
"os"
"path/filepath"
"testing"
)
func TestCheckHTMLSanitize_RegexStrip(t *testing.T) {
dir := t.TempDir()
writeFile(t, dir, "bad.go", `package foo
import "regexp"
func clean(s string) string {
re := regexp.MustCompile(`+"`"+`<[^>]*>`+"`"+`)
return re.ReplaceAllString(s, "")
}
`)
vs := checkHTMLSanitize(dir)
if len(vs) == 0 {
t.Fatal("expected regex-html-strip violation")
}
if vs[0].rule != "regex-html-strip" {
t.Fatalf("expected rule regex-html-strip, got %s", vs[0].rule)
}
}
func TestCheckHTMLSanitize_ScriptRegex(t *testing.T) {
dir := t.TempDir()
writeFile(t, dir, "bad.go", `package foo
import "regexp"
func clean(s string) string {
re := regexp.MustCompile(`+"`"+`(?s)`+"`"+`)
return re.ReplaceAllString(s, "")
}
`)
vs := checkHTMLSanitize(dir)
if len(vs) == 0 {
t.Fatal("expected regex-html-strip violation for