feat(chat): support line breaks and pasted content. Closes #3108
This commit is contained in:
@@ -149,7 +149,7 @@ func sanitize(raw string) string {
|
||||
// Allow breaks
|
||||
p.AllowElements("br")
|
||||
|
||||
p.AllowElementsContent("p")
|
||||
p.AllowElements("p")
|
||||
|
||||
// Allow img tags from the the local emoji directory only
|
||||
p.AllowAttrs("src").Matching(_sanitizeReSrcMatch).OnElements("img")
|
||||
|
||||
@@ -16,11 +16,11 @@ Here is an iframe<iframe src="http://yahoo.com"></iframe>
|
||||
[test link](http://owncast.online)
|
||||
<img class="emoji" src="/img/emoji/bananadance.gif">`
|
||||
|
||||
expected := `Test one two three! I go to <a href="http://yahoo.com" rel="nofollow noreferrer noopener" target="_blank">http://yahoo.com</a> and search for <em>sports</em> and <strong>answers</strong>.
|
||||
Here is an iframe
|
||||
expected := `<p>Test one two three! I go to <a href="http://yahoo.com" rel="nofollow noreferrer noopener" target="_blank">http://yahoo.com</a> and search for <em>sports</em> and <strong>answers</strong>.
|
||||
Here is an iframe</p>
|
||||
blah blah blah
|
||||
<a href="http://owncast.online" rel="nofollow noreferrer noopener" target="_blank">test link</a>
|
||||
<img class="emoji" src="/img/emoji/bananadance.gif">`
|
||||
<p><a href="http://owncast.online" rel="nofollow noreferrer noopener" target="_blank">test link</a>
|
||||
<img class="emoji" src="/img/emoji/bananadance.gif"></p>`
|
||||
|
||||
result := events.RenderAndSanitize(messageContent)
|
||||
if result != expected {
|
||||
@@ -31,7 +31,7 @@ blah blah blah
|
||||
// Test to make sure we block remote images in chat messages.
|
||||
func TestBlockRemoteImages(t *testing.T) {
|
||||
messageContent := `<img src="https://via.placeholder.com/img/emoji/350x150"> test `
|
||||
expected := `test`
|
||||
expected := `<p> test </p>`
|
||||
result := events.RenderAndSanitize(messageContent)
|
||||
|
||||
if result != expected {
|
||||
@@ -42,7 +42,7 @@ func TestBlockRemoteImages(t *testing.T) {
|
||||
// Test to make sure emoji images are allowed in chat messages.
|
||||
func TestAllowEmojiImages(t *testing.T) {
|
||||
messageContent := `<img alt=":beerparrot:" title=":beerparrot:" src="/img/emoji/beerparrot.gif"> test `
|
||||
expected := `<img alt=":beerparrot:" title=":beerparrot:" src="/img/emoji/beerparrot.gif"> test <img src="/img/emoji/beerparrot.gif">`
|
||||
expected := `<p><img alt=":beerparrot:" title=":beerparrot:" src="/img/emoji/beerparrot.gif"> test <img src="/img/emoji/beerparrot.gif"></p>`
|
||||
result := events.RenderAndSanitize(messageContent)
|
||||
|
||||
if result != expected {
|
||||
|
||||
Reference in New Issue
Block a user