1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00

Make links clickable in text view of emails

This commit is contained in:
James Hillyerd
2012-10-27 15:24:29 -07:00
parent e9bde25790
commit 69d0e6c341
2 changed files with 28 additions and 7 deletions

View File

@@ -2,18 +2,28 @@ package web
import (
"github.com/stretchrcom/testify/assert"
"html/template"
"testing"
)
func TestTextToHtml(t *testing.T) {
// Identity
assert.Equal(t, textToHtml("html"), "html")
assert.Equal(t, textToHtml("html"), template.HTML("html"))
// Check it escapes
assert.Equal(t, textToHtml("<html>"), "&lt;html&gt;")
assert.Equal(t, textToHtml("<html>"), template.HTML("&lt;html&gt;"))
// Check for linebreaks
assert.Equal(t, textToHtml("line\nbreak"), "line<br/>\nbreak")
assert.Equal(t, textToHtml("line\r\nbreak"), "line<br/>\nbreak")
assert.Equal(t, textToHtml("line\rbreak"), "line<br/>\nbreak")
assert.Equal(t, textToHtml("line\nbreak"), template.HTML("line<br/>\nbreak"))
assert.Equal(t, textToHtml("line\r\nbreak"), template.HTML("line<br/>\nbreak"))
assert.Equal(t, textToHtml("line\rbreak"), template.HTML("line<br/>\nbreak"))
}
func TestURLDetection(t *testing.T) {
assert.Equal(t,
textToHtml("http://google.com/"),
template.HTML("<a href=\"http://google.com/\" target=\"_blank\">http://google.com/</a>"))
assert.Equal(t,
textToHtml("http://a.com/?q=a&n=v"),
template.HTML("<a href=\"http://a.com/?q=a&n=v\" target=\"_blank\">http://a.com/?q=a&amp;n=v</a>"))
}