Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4400 from gratipay/rtlo
Browse files Browse the repository at this point in the history
Add rtlo_scrub()
  • Loading branch information
rohitpaulk authored Jun 16, 2017
2 parents f7b9166 + 0aeb172 commit 9751637
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gratipay/utils/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ def render_and_scrub(markdown):
"""Given markdown, return a Markup with tags stripped and everything else
escaped.
"""
return Markup.escape(render(markdown).striptags())
u_right_to_left_override = "\u202E"
right_to_left_override = "‮"
replacements = (right_to_left_override, ''), (u_right_to_left_override, '')
rtlo_gone = reduce(lambda a, kv: a.replace(*kv), replacements, markdown)
return Markup.escape(render(rtlo_gone).striptags())
3 changes: 3 additions & 0 deletions tests/py/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def test_scrubs_comments(self):
def test_renders_entity_references(self):
assert markdown.render_and_scrub('™') == '\u2122'

def test_scrubs_rtlo(self):
assert markdown.render_and_scrub('ed.io/about‮3p\u202Em.exe') == 'ed.io/about3pm.exe'

def test_render_does_not_render_entity_references_it_really_is_striptags(self):
assert markdown.render('&trade;') == '<p>&trade;</p>\n'
assert markdown.render_and_scrub('&trade;') == '\u2122'
Expand Down

0 comments on commit 9751637

Please sign in to comment.