From db6ae707ef5b04e6d1bcc0a40fe15dcd96de4fb0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 27 Feb 2024 12:58:08 +0100 Subject: [PATCH] Add some tests for add_image_title I'm not sure if the behaviour is expected, but I didn't manage to get the content injection to work in my browser, so I guess it's alright? --- internal/reader/rewrite/rewriter_test.go | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/reader/rewrite/rewriter_test.go b/internal/reader/rewrite/rewriter_test.go index 3910ccd4..fa2b765b 100644 --- a/internal/reader/rewrite/rewriter_test.go +++ b/internal/reader/rewrite/rewriter_test.go @@ -671,3 +671,35 @@ func TestAddHackerNewsLinksUsingOpener(t *testing.T) { t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry) } } + +func TestAddImageTitle(t *testing.T) { + testEntry := &model.Entry{ + Title: `A title`, + Content: ` + + "onerror=alert(1) a=" + "onerror=alert(1) a=" + ;"onerror=alert(1) a=;" + pouf + pouf + pouf + `, + } + + controlEntry := &model.Entry{ + Title: `A title`, + Content: `

pouf

+

pouf

+

pouf

+
;"onerror=alert(1) a=;"

pouf

+
pouf

"onerror=alert(1) a="

+
pouf

"onerror=alert(1) a="

+
pouf

;"onerror=alert(1) a=;"

+ `, + } + Rewriter("https://example.org/article", testEntry, `add_image_title`) + + if !reflect.DeepEqual(testEntry, controlEntry) { + t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry) + } +}