diff --git a/helpers/content.go b/helpers/content.go index 802187bc4..96e84e5cf 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -37,9 +37,9 @@ func StripHTML(s string) string { output = s } else { s = strings.Replace(s, "\n", " ", -1) - s = strings.Replace(s, "

", " \n", -1) - s = strings.Replace(s, "
", " \n", -1) - s = strings.Replace(s, "
", " \n", -1) + s = strings.Replace(s, "

", "\n", -1) + s = strings.Replace(s, "
", "\n", -1) + s = strings.Replace(s, "
", "\n", -1) //
is the xhtml line break tag // Walk through the string removing all tags b := new(bytes.Buffer) diff --git a/helpers/general_test.go b/helpers/general_test.go new file mode 100644 index 000000000..18cdfcc5d --- /dev/null +++ b/helpers/general_test.go @@ -0,0 +1,22 @@ +package helpers + +import ( + "testing" +) + +func TestStripHTML(t *testing.T) { + type test struct { + input, expected string + } + data := []test{ + {"

strip h1 tag

", "strip h1 tag "}, + {"

strip p tag

", " strip p tag \n"}, + {"
strip br
", " strip br\n"}, + } + for i, d := range data { + output := StripHTML(d.input) + if d.expected != output { + t.Errorf("Test %d failed. Expected %q got %q", i, d.expected, output) + } + } +}