From 29c1bd6202ca517504b34fb741b4b4eaaa435d62 Mon Sep 17 00:00:00 2001 From: Ali Akbar <52413434+Ali-D-Akbar@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:58:06 +0500 Subject: [PATCH] fix: avoid span tags overlapping (#4330) --- course_discovery/apps/course_metadata/tests/test_utils.py | 2 ++ course_discovery/apps/course_metadata/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/course_discovery/apps/course_metadata/tests/test_utils.py b/course_discovery/apps/course_metadata/tests/test_utils.py index a4f35d8808..67cf955213 100644 --- a/course_discovery/apps/course_metadata/tests/test_utils.py +++ b/course_discovery/apps/course_metadata/tests/test_utils.py @@ -807,6 +807,8 @@ class UtilsTests(TestCase): ('
with lang
', 'with lang
'), ('lang and class
', 'lang and class
'), ('class only
', 'class only
'), + ('1 span tag inside RTL p
', '1 span tag inside RTL p
'), + ('multiple span tags inside RTL p
', 'multiple span tags inside RTL p
'), # A sample text from real life when pasting from Microsoft Word into a rich text editor # pylint: disable=line-too-long diff --git a/course_discovery/apps/course_metadata/utils.py b/course_discovery/apps/course_metadata/utils.py index 99bb240ec0..3c945db836 100644 --- a/course_discovery/apps/course_metadata/utils.py +++ b/course_discovery/apps/course_metadata/utils.py @@ -732,7 +732,7 @@ def handle_tag(self, tag, attrs, start): if not self.is_p_tag_with_dir: super().handle_tag(tag, attrs, start) - elif tag not in HTML_TAGS_ATTRIBUTE_WHITELIST: + elif tag not in HTML_TAGS_ATTRIBUTE_WHITELIST and tag != 'span': if start: self.outtextf(f'<{tag}') if attrs: @@ -743,7 +743,7 @@ def handle_tag(self, tag, attrs, start): self.outtextf(f'{tag}>') if tag == 'span': - if attrs and start and 'lang' in dict(attrs): + if attrs and start and not self.in_lang_span and 'lang' in dict(attrs): self.outtextf(f'') self.in_lang_span = True if not start and self.in_lang_span: