~netlandish/links-dev

links: Strip tags from link description input. Also use <br /> tags when displaying newlines to fix formatting issues. v1 APPLIED

Peter Sanchez: 1
 Strip tags from link description input. Also use <br /> tags when displaying newlines to fix formatting issues.

 4 files changed, 11 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/95/mbox | git am -3
Learn more about email & git

[PATCH links] Strip tags from link description input. Also use <br /> tags when displaying newlines to fix formatting issues. Export this patch

Fixes: Formatting issues when displaying notes.
Signed-off-by: Peter Sanchez <peter@netlandish.com>
---
Depends on the gobwebs bump patch sent previously

 api/graph/schema.resolvers.go | 7 ++++---
 cmd/links/main.go             | 3 +++
 cmd/test/helpers.go           | 3 +++
 templates/link_detail.html    | 2 +-
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index 12a40c4..8e7f7d0 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -41,6 +41,7 @@ import (
	"netlandish.com/x/gobwebs"
	oauth2 "netlandish.com/x/gobwebs-oauth2"
	gaccounts "netlandish.com/x/gobwebs/accounts"
	gcore "netlandish.com/x/gobwebs/core"
	"netlandish.com/x/gobwebs/crypto"
	"netlandish.com/x/gobwebs/database"
	"netlandish.com/x/gobwebs/email"
@@ -319,7 +320,7 @@ func (r *mutationResolver) AddLink(ctx context.Context, input *model.LinkInput)
		Hash:       ksuid.New().String(),
	}
	if input.Description != nil {
		OrgLink.Description = *input.Description
		OrgLink.Description = gcore.StripHtmlTags(*input.Description)
	}

	err = OrgLink.Store(ctx)
@@ -490,7 +491,7 @@ func (r *mutationResolver) UpdateLink(ctx context.Context, input *model.UpdateLi
		orgLink.Title = *input.Title
	}
	if input.Description != nil {
		orgLink.Description = *input.Description
		orgLink.Description = gcore.StripHtmlTags(*input.Description)
	}

	if input.Unread != nil {
@@ -736,7 +737,7 @@ func (r *mutationResolver) AddNote(ctx context.Context, input *model.NoteInput)
	OrgLinkNote := &models.OrgLink{
		Title:       input.Title,
		OrgID:       org.ID,
		Description: input.Description,
		Description: gcore.StripHtmlTags(input.Description),
		BaseURLID:   sql.NullInt64{Valid: BaseURL.ID > 0, Int64: int64(BaseURL.ID)},
		Visibility:  string(input.Visibility),
		Starred:     input.Starred,
diff --git a/cmd/links/main.go b/cmd/links/main.go
index 57bc96d..c911962 100644
--- a/cmd/links/main.go
+++ b/cmd/links/main.go
@@ -292,6 +292,9 @@ func run() error {
		},
		"addQueryElement": links.AddQueryElement,
		"getAddLinkURL":   links.GetAddLinkURL,
		"newlinebr": func(blob string) string {
			return strings.ReplaceAll(blob, "\n", "<br />\n")
		},
	})
	srv.TemplateAllowOverride(
		"seoData",
diff --git a/cmd/test/helpers.go b/cmd/test/helpers.go
index 382ecf6..3f2651c 100644
--- a/cmd/test/helpers.go
+++ b/cmd/test/helpers.go
@@ -132,6 +132,9 @@ func NewWebTestServer(t *testing.T) (*server.Server, *echo.Echo) {
		},
		"addQueryElement": links.AddQueryElement,
		"getAddLinkURL":   links.GetAddLinkURL,
		"newlinebr": func(blob string) string {
			return strings.ReplaceAll(blob, "\n", "<br />\n")
		},
	})
	err = srv.LoadTemplatesFS(links.TemplateFS, "templates/*.html", "templates/*.txt")
	if err != nil {
diff --git a/templates/link_detail.html b/templates/link_detail.html
index ea3002b..08ca228 100644
--- a/templates/link_detail.html
+++ b/templates/link_detail.html
@@ -31,7 +31,7 @@
  {{ if eq .link.Type "LINK" }}
  <p><a href="{{reverse "core:link_redirect" .link.Hash}}" target="_blank">{{stripCommonProtocol .link.URL}}</a></p>
  {{end}}
  <p>{{.link.Description}}</p>
  <p>{{ htmlSafe (newlinebr .link.Description) }}</p>
  {{if .link.Tags}}
  <p>{{.pd.Data.tags}}:</p>
  <div class="link-tag">
-- 
2.47.2
Applied.

To git@git.code.netlandish.com:~netlandish/links
   9c585ef..0c2ce95  master -> master