don't clean \n and \t

This commit is contained in:
Umputun
2018-05-06 18:07:54 -05:00
parent 1aa43ff9a9
commit 80bac9d951
2 changed files with 29 additions and 3 deletions
+27
View File
@@ -70,6 +70,33 @@ func TestServer_Preview(t *testing.T) {
assert.Equal(t, "<p>test 123</p>", string(b))
}
func TestServer_PreviewWithMD(t *testing.T) {
srv, port := prep(t)
require.NotNil(t, srv)
defer cleanup(srv)
text := `
# h1
BKT
func TestServer_Preview(t *testing.T) {
srv, port := prep(t)
require.NotNil(t, srv)
}
BKT
`
text = strings.Replace(text, "BKT", "```", -1)
j := fmt.Sprintf(`{"text": "%s", "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`, text)
j = strings.Replace(j, "\n", "\\n", -1)
t.Log(j)
r := strings.NewReader(j)
resp, err := http.Post(fmt.Sprintf("http://127.0.0.1:%d/api/v1/preview", port), "application/json", r)
assert.Equal(t, http.StatusOK, resp.StatusCode)
b, err := ioutil.ReadAll(resp.Body)
assert.Nil(t, err)
assert.Equal(t, "<h1>h1</h1>\n\n<pre><code>func TestServer_Preview(t *testing.T) {\nsrv, port := prep(t)\n require.NotNil(t, srv)\n}\n</code></pre>\n", string(b))
}
func TestServer_CreateAndGet(t *testing.T) {
srv, port := prep(t)
assert.NotNil(t, srv)
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"html/template"
"log"
"strconv"
"strings"
"time"
"github.com/microcosm-cc/bluemonday"
@@ -92,8 +91,8 @@ func (c *Comment) Sanitize() {
c.User.Name = template.HTMLEscapeString(c.User.Name)
c.User.Picture = p.Sanitize(c.User.Picture)
c.Text = strings.Replace(c.Text, "\n", "", -1)
c.Text = strings.Replace(c.Text, "\t", "", -1)
// c.Text = strings.Replace(c.Text, "\n", "", -1)
// c.Text = strings.Replace(c.Text, "\t", "", -1)
}
// hashIP replace sensitive fields with hashes