From ebe3dc5e12d584d7140acd07933e7de1408f63ce Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:47:08 +0500 Subject: [PATCH] fix: fixed course update notification UI in notification tray (#35715) --- cms/djangoapps/contentstore/tests/test_utils.py | 15 +++++++++++++++ cms/djangoapps/contentstore/utils.py | 2 ++ 2 files changed, 17 insertions(+) diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index 2c5be351fc50..a91379797060 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -974,3 +974,18 @@ def test_if_content_is_plain_text(self): assert Notification.objects.all().count() == 1 notification = Notification.objects.first() assert notification.content == "

content Sub content heading

" + + def test_if_html_unescapes(self): + """ + Tests if html unescapes when creating content of course update notification + """ + user = UserFactory() + CourseEnrollment.enroll(user=user, course_key=self.course.id) + assert Notification.objects.all().count() == 0 + content = "

<p> &nbsp;</p>
"\ + "<p>abcd</p>
"\ + "<p>&nbsp;</p>

" + send_course_update_notification(self.course.id, content, self.user) + assert Notification.objects.all().count() == 1 + notification = Notification.objects.first() + assert notification.content == "

abcd

" diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 964f0c57e757..df1d1e27b405 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -3,6 +3,7 @@ """ from __future__ import annotations import configparser +import html import logging import re from collections import defaultdict @@ -2258,6 +2259,7 @@ def clean_html_body(html_body): """ Get html body, remove tags and limit to 500 characters """ + html_body = html.unescape(html_body).strip() html_body = BeautifulSoup(Truncator(html_body).chars(500, html=True), 'html.parser') text_content = html_body.get_text(separator=" ").strip() text_content = text_content.replace('\n', '').replace('\r', '')