Fix hashtagging of HTML entities
This commit is contained in:
		
							parent
							
								
									4420507f62
								
							
						
					
					
						commit
						fb342cfb54
					
				@ -123,7 +123,7 @@ class Hashtag(StatorModel):
 | 
			
		||||
        delete = "{edit}delete/"
 | 
			
		||||
        timeline = "/tags/{self.hashtag}/"
 | 
			
		||||
 | 
			
		||||
    hashtag_regex = re.compile(r"((?:\B#)([a-zA-Z0-9(_)]{1,}\b))")
 | 
			
		||||
    hashtag_regex = re.compile(r"\B#([a-zA-Z0-9(_)]+\b)(?!;)")
 | 
			
		||||
 | 
			
		||||
    def save(self, *args, **kwargs):
 | 
			
		||||
        self.hashtag = self.hashtag.lstrip("#")
 | 
			
		||||
@ -182,7 +182,7 @@ class Hashtag(StatorModel):
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def linkify_hashtags(cls, content) -> str:
 | 
			
		||||
        def replacer(match):
 | 
			
		||||
            hashtag = match.group()
 | 
			
		||||
            return f'<a class="hashtag" href="/tags/{hashtag.lstrip("#").lower()}/">{hashtag}</a>'
 | 
			
		||||
            hashtag = match.group(1)
 | 
			
		||||
            return f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>'
 | 
			
		||||
 | 
			
		||||
        return mark_safe(Hashtag.hashtag_regex.sub(replacer, content))
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
from core.html import html_to_plaintext
 | 
			
		||||
from core.html import html_to_plaintext, sanitize_post
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_html_to_plaintext():
 | 
			
		||||
@ -13,3 +13,9 @@ def test_html_to_plaintext():
 | 
			
		||||
        html_to_plaintext("<p>Hi!</p>\n\n<p>How are<br> you?</p><p>today</p>")
 | 
			
		||||
        == "Hi!\n\nHow are\n you?\n\ntoday"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_sanitize_post():
 | 
			
		||||
 | 
			
		||||
    assert sanitize_post("<p>Hello!</p>") == "<p>Hello!</p>"
 | 
			
		||||
    assert sanitize_post("<p>It's great</p>") == "<p>It's great</p>"
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user