commit edde12d186263ac341ed47a7271a775897f80a55
parent 7e5f6b0e92f25fc0cabd8ed42a22510bba80ccd5
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 15 Nov 2022 22:34:56 -0500
auto fix onion links that are missing http scheme
Diffstat:
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/pkg/web/handlers/api/v1/msgInterceptor.go b/pkg/web/handlers/api/v1/msgInterceptor.go
@@ -70,6 +70,7 @@ func ProcessRawMessage(in, roomKey string, authUserID, roomID int64, upload *dat
html = convertPGPMessageToFile(html, authUserID)
html = convertPGPPublicKeyToFile(html, authUserID)
html = convertAgeMessageToFile(html, authUserID)
+ html = convertLinksWithoutScheme(html)
html = convertMarkdown(html)
html = convertBangShortcuts(html)
html = convertArchiveLinks(html, roomID, authUserID)
diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go
@@ -801,6 +801,15 @@ func styleQuote(origHtml string, quoted *database.ChatMessage) (html string) {
return html
}
+var noSchemeOnionLinkRgx = regexp.MustCompile(`\s[a-z2-7]{56}.onion`)
+
+func convertLinksWithoutScheme(in string) string {
+ html := noSchemeOnionLinkRgx.ReplaceAllStringFunc(in, func(s string) string {
+ return " http://" + strings.TrimSpace(s)
+ })
+ return html
+}
+
var youtubeComIDRgx = regexp.MustCompile(`watch\?v=([\w-]+)`)
var youtubeComShosrtsIDRgx = regexp.MustCompile(`/shorts/([\w-]+)`)
var youtuBeIDRgx = regexp.MustCompile(`https://youtu\.be/([\w-]+)`)