From 80bac9d951a0e87483675f48d36048c8515e91e0 Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 6 May 2018 18:07:54 -0500 Subject: [PATCH] don't clean \n and \t --- app/rest/api/rest_test.go | 27 +++++++++++++++++++++++++++ app/store/comment.go | 5 ++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/rest/api/rest_test.go b/app/rest/api/rest_test.go index b5dc7668..0c1e2064 100644 --- a/app/rest/api/rest_test.go +++ b/app/rest/api/rest_test.go @@ -70,6 +70,33 @@ func TestServer_Preview(t *testing.T) { assert.Equal(t, "

test 123

", 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

\n\n
func TestServer_Preview(t *testing.T) {\nsrv, port := prep(t)\n  require.NotNil(t, srv)\n}\n
\n", string(b)) +} + func TestServer_CreateAndGet(t *testing.T) { srv, port := prep(t) assert.NotNil(t, srv) diff --git a/app/store/comment.go b/app/store/comment.go index f179019e..de1b551d 100644 --- a/app/store/comment.go +++ b/app/store/comment.go @@ -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