File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -936,3 +936,27 @@ def test_update_project_tab_item(self):
936936 ),
937937 content ["content" ],
938938 )
939+
940+ def test_html_escape_char (self ):
941+ self .client .force_authenticate (self .user )
942+ title = "this is a & title with many & char"
943+ description = "<p>this is a & description with many & char</p>"
944+ purpose = "this is a & purpose with many & char"
945+ payload = {
946+ "title" : title ,
947+ "description" : description ,
948+ "is_locked" : faker .boolean (),
949+ "is_shareable" : faker .boolean (),
950+ "purpose" : purpose ,
951+ "organizations_codes" : [self .organization .code ],
952+ "images_ids" : [],
953+ }
954+ response = self .client .post (reverse ("Project-list" ), data = payload )
955+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
956+ content = response .json ()
957+
958+ self .assertEqual (content ["title" ], title )
959+ # description is a html field so all & is escaped
960+ description = "<p>this is a & description with many & char</p>"
961+ self .assertEqual (content ["description" ], description )
962+ self .assertEqual (content ["purpose" ], purpose )
Original file line number Diff line number Diff line change 11import base64
22import gc
3+ import html
34import io
45import itertools
56import uuid
@@ -69,14 +70,16 @@ def iter_img_b64(soup: BeautifulSoup):
6970 yield img
7071
7172
72- def remove_images_text (text : str ) -> str :
73+ def remove_images_text (text : str , unescape = True ) -> str :
7374 """Process rich text sent by the frontend.
7475 Some texts can contain images
7576
7677 Parameters
7778 ----------
7879 text : str
7980 The text to process.
81+ escape : bool
82+ escape html entities in text
8083
8184 Returns
8285 -------
@@ -87,6 +90,9 @@ def remove_images_text(text: str) -> str:
8790
8891 for img in iter_img_b64 (soup ):
8992 img .decompose ()
93+
94+ if unescape :
95+ return html .unescape (str (soup ))
9096 return str (soup )
9197
9298
You can’t perform that action at this time.
0 commit comments