Don't linkify hashtags in usernames and metadata

Fixes #228
This commit is contained in:
Andrew Godwin 2022-12-22 01:10:25 +00:00
parent 578b504c92
commit ca3dc82a62
2 changed files with 20 additions and 6 deletions

View file

@ -92,9 +92,9 @@ class ContentRenderer:
html = self.imageify_emojis(html, identity=post.author)
return mark_safe(html)
def render_identity(self, html: str, identity, strip: bool = False) -> str:
def render_identity_summary(self, html: str, identity, strip: bool = False) -> str:
"""
Given identity field HTML, normalises it and renders it for presentation.
Given identity summary HTML, normalises it and renders it for presentation.
"""
if not html:
return ""
@ -107,6 +107,20 @@ class ContentRenderer:
html = self.imageify_emojis(html, identity=identity)
return mark_safe(html)
def render_identity_data(self, html: str, identity, strip: bool = False) -> str:
"""
Given name/basic value HTML, normalises it and renders it for presentation.
"""
if not html:
return ""
if strip:
html = strip_html(html)
else:
html = sanitize_html(html)
if self.local:
html = self.imageify_emojis(html, identity=identity)
return mark_safe(html)
def linkify_mentions(self, html: str, post) -> str:
"""
Links mentions _in the context of the post_ - as in, using the mentions

View file

@ -283,7 +283,7 @@ class Identity(StatorModel):
@property
def safe_summary(self):
return ContentRenderer(local=True).render_identity(self.summary, self)
return ContentRenderer(local=True).render_identity_summary(self.summary, self)
@property
def safe_metadata(self):
@ -293,8 +293,8 @@ class Identity(StatorModel):
return []
return [
{
"name": renderer.render_identity(data["name"], self, strip=True),
"value": renderer.render_identity(data["value"], self, strip=True),
"name": renderer.render_identity_data(data["name"], self, strip=True),
"value": renderer.render_identity_data(data["value"], self, strip=True),
}
for data in self.metadata
]
@ -367,7 +367,7 @@ class Identity(StatorModel):
"""
Return the name_or_handle with any HTML substitutions made
"""
return ContentRenderer(local=True).render_identity(
return ContentRenderer(local=True).render_identity_data(
self.name_or_handle, self, strip=True
)