Received: from mail.netlandish.com (mail.netlandish.com [174.136.98.166])
	by code.netlandish.com (Postfix) with ESMTP id D68DC270
	for <~netlandish/links-dev@lists.code.netlandish.com>; Mon, 10 Feb 2025 13:48:25 +0000 (UTC)
Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.128.180; helo=mail-yw1-f180.google.com; envelope-from=peter@netlandish.com; receiver=<UNKNOWN> 
Authentication-Results: mail.netlandish.com;
	dkim=pass (1024-bit key; unprotected) header.d=netlandish.com header.i=@netlandish.com header.b=glUKi9/+
Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180])
	by mail.netlandish.com (Postfix) with ESMTP id 842D71D80C0
	for <~netlandish/links-dev@lists.code.netlandish.com>; Mon, 10 Feb 2025 13:55:48 +0000 (UTC)
Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6f768e9be1aso45376217b3.0
        for <~netlandish/links-dev@lists.code.netlandish.com>; Mon, 10 Feb 2025 05:55:48 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=netlandish.com; s=google; t=1739195748; x=1739800548; darn=lists.code.netlandish.com;
        h=content-transfer-encoding:mime-version:message-id:date:subject:to
         :from:from:to:cc:subject:date:message-id:reply-to;
        bh=wj5m8/DSYUHGv0p/KkdE8LSuYh+91Yq2M6W0z5elENI=;
        b=glUKi9/+kxDAKS9oiiapCF3+Nr1Z+SRo3SS8QzFDJE/5M03mTx/p148VEaCT0gI9lf
         ha8F68s6e6ZbBwkgOzGGw18KqZu/kqx3G/+gRK/fOtCwxUvUPwKCeUmF9CPTBqDkNhaP
         VhKYhxchtakFmR5szMrvx+RExXrTfcYhwtFxI=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1739195748; x=1739800548;
        h=content-transfer-encoding:mime-version:message-id:date:subject:to
         :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
        bh=wj5m8/DSYUHGv0p/KkdE8LSuYh+91Yq2M6W0z5elENI=;
        b=rnQoosPTToMi7wxf4pnNV+wK6YKEs2NaaM5L+Etg37dknKcJda25vkLmjDa9FXCx9/
         qnuPhB3Dw/oEAvKxrN9UD2FYRKZ6s3qPeci9TkXEf7NpCKTi31dIvJS5zEvF4PpB6BwY
         pO0KTYxIUUXiAvbW8ClRH0ycGuvgloJXSn5rQoHD+j3FPWoJvEs58d0+5PVLyQbg9pLD
         uLg7ECYO0WPPQBwR9ioSc6YVN+2Jtkke//jNVRFqnIyiIv8uUO/5/shPWmD5JHgN5JKC
         AVitMl//sWsg2837qICiE8J+14tQVXbcIZIYiShLlH8V9tdlegsUOaRj2ZFAQ9WQkHx/
         JVpA==
X-Gm-Message-State: AOJu0YxpVmDx6y5hgdtA9scGkWd1XN08LmnJzMupD2z+cpc6anudXfr+
	t2Gbza6pMQj4A5FKjM6aV8oeI/jk65od1ajJ100Z45hA4rQ2VucgZY87AC9LY0o5Ji8VffXCux+
	WZj8=
X-Gm-Gg: ASbGncvybtU5XltVn4QUQJPoIQWKYAjHQo7JTE5RHAIIa8lPBp/DU6G1zhLUBq0jjy9
	Op2SIqgG3YC1eYtQrX8yZQ8zAInJK7xHdeg7jBba/y1sGNW8tQCMumemCwHypn2yAiva/55BFMb
	Dt0lpcltJ1Vzg3KSMNKnfVZxhQwLjUzaV3E+4sqpoxYQvU0JqpeO7qxZFlLDVWUh2YnzpvwFt21
	Vri2A4m7sudJ7Lw0cRrq6Sli8a7Jfgi0RPE42JO0kVLJXDlWUXFdBXUYc7DmXrOBvtbrB/j9MWp
	4NaAtGP4XIKH2/2M
X-Google-Smtp-Source: AGHT+IHNKnkDtw2Vh35jmAv6Gt6HXXrYYbldYHGXTC4LnbwLiU7JJRh+uubAh3Huf2ug5EcJVEVqCQ==
X-Received: by 2002:a05:690c:4b86:b0:6f9:4244:329f with SMTP id 00721157ae682-6f9b38415fdmr108882317b3.7.1739195747703;
        Mon, 10 Feb 2025 05:55:47 -0800 (PST)
Received: from localhost ([2803:2d60:1107:87f:3035:53de:5695:5818])
        by smtp.gmail.com with ESMTPSA id 00721157ae682-6f99fd1fa90sm16518667b3.45.2025.02.10.05.55.46
        for <~netlandish/links-dev@lists.code.netlandish.com>
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 10 Feb 2025 05:55:47 -0800 (PST)
From: Peter Sanchez <peter@netlandish.com>
To: ~netlandish/links-dev@lists.code.netlandish.com
Subject: [PATCH links] Strip tags from link description input. Also use <br /> tags when displaying newlines to fix formatting issues.
Date: Mon, 10 Feb 2025 07:55:28 -0600
Message-ID: <20250210135544.6118-1-peter@netlandish.com>
X-Mailer: git-send-email 2.47.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

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

