aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/search_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/search_test.go')
-rw-r--r--internal/web/search_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/web/search_test.go b/internal/web/search_test.go
index 6a9b0a5..6ced39b 100644
--- a/internal/web/search_test.go
+++ b/internal/web/search_test.go
@@ -4,6 +4,8 @@ import (
"regexp"
"strings"
"testing"
+
+ "github.com/gramanas/blogspace/internal/store"
)
func TestSearchPattern(t *testing.T) {
@@ -42,3 +44,14 @@ func TestSearchSnippet(t *testing.T) {
t.Errorf("title-only snippet: %q", got)
}
}
+
+func TestSnippetSource(t *testing.T) {
+ p := &store.Post{Format: store.FormatHTML, BodyMD: `<p class="x">Tom &amp; <b>Jerry</b></p><script>alert(1)</script>`}
+ if got := snippetSource(p); got != "Tom & Jerry" {
+ t.Errorf("html post: %q", got)
+ }
+ p.Format = store.FormatMarkdown
+ if got := snippetSource(p); got != p.BodyMD {
+ t.Errorf("markdown post is used as written: %q", got)
+ }
+}