File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed
Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 88- Improve developement instructions (@marteinn )
99- Make sure title and descriptions are truncated if too long (@marteinn )
1010- Strip html tags from preview widget (@marteinn )
11+ - Strip html tags from get_title/get_description in settings (@marteinn )
1112
1213### Fixed
1314- Fix broken image preview #12 (@marteinn )
Original file line number Diff line number Diff line change @@ -109,3 +109,16 @@ def test_title_and_description_trunctation(self):
109109
110110 self .assertEqual (len (google_settings .get_title ()), 70 )
111111 self .assertEqual (len (google_settings .get_description ()), 160 )
112+
113+ def test_that_html_tags_are_stripped (self ):
114+ google_settings = GoogleSettings (self .google_page )
115+
116+ meta_settings .META_PREVIEW_GOOGLE_TITLE_FIELDS = "seo_title"
117+ meta_settings .META_PREVIEW_GOOGLE_DESCRIPTION_FIELDS = "search_description"
118+
119+ self .google_page .seo_title = "<strong>Hello world</strong> and <em>earth</em>"
120+ self .google_page .search_description = "<p>My description</p>"
121+ self .google_page .save ()
122+
123+ self .assertEqual (google_settings .get_title (), "Hello world and earth" )
124+ self .assertEqual (google_settings .get_description (), "My description" )
Original file line number Diff line number Diff line change 11from typing import Union , Literal
22
33from django .utils .text import Truncator
4+ from django .utils .html import strip_tags
45
56from . import meta_settings
67
@@ -65,6 +66,8 @@ def get_title(self) -> str:
6566 return ""
6667
6768 value = getattr (self .instance , title_field ) or ""
69+ value = strip_tags (value )
70+
6871 if self .title_max_chars == - 1 :
6972 return value
7073
@@ -90,6 +93,8 @@ def get_description(self):
9093 return ""
9194
9295 value = getattr (self .instance , description_field ) or ""
96+ value = strip_tags (value )
97+
9398 if self .description_max_chars == - 1 :
9499 return value
95100
You can’t perform that action at this time.
0 commit comments