Skip to content

Commit

Permalink
fix: avoid span tags overlapping (#4330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-D-Akbar authored Apr 23, 2024
1 parent 1dbe48b commit 29c1bd6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ class UtilsTests(TestCase):
('<p><span lang="en">with lang</span></p>', '<p><span lang="en">with lang</span></p>'),
('<p><span class="body" lang="en">lang and class</span></p>', '<p><span lang="en">lang and class</span></p>'),
('<p><span class="body">class only</span></p>', '<p>class only</p>'),
('<p dir="rtl"><span lang="en">1 span tag inside RTL p</span></p>', '<p dir="rtl"><span lang="en">1 span tag inside RTL p</span></p>'),
('<p dir="rtl"><span lang="en"><span lang="en"><span lang="en">multiple span tags inside RTL p</span></span></span></p>', '<p dir="rtl"><span lang="en">multiple span tags inside RTL p</span></p>'),
# A sample text from real life when pasting from Microsoft Word into a rich text editor
# pylint: disable=line-too-long
Expand Down
4 changes: 2 additions & 2 deletions course_discovery/apps/course_metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'<span lang="{dict(attrs)["lang"]}">')
self.in_lang_span = True
if not start and self.in_lang_span:
Expand Down

0 comments on commit 29c1bd6

Please sign in to comment.