# HG changeset patch # User Ludovic Chabant # Date 1567984044 25200 # Node ID aa8f10e9ab55257b8afc2ee9ad737d9e1a2d10b2 # Parent 431cc200d526573813b598557f2d0bef35076f6d Escape special characters. diff -r 431cc200d526 -r aa8f10e9ab55 silorider/format.py --- a/silorider/format.py Wed Jan 23 08:10:27 2019 -0800 +++ b/silorider/format.py Sun Sep 08 16:07:24 2019 -0700 @@ -75,9 +75,13 @@ self.urls = [] +def _escape_percents(txt): + return txt.replace('%', '%%') + + def _do_strip_html(elem, ctx): if isinstance(elem, bs4.NavigableString): - return str(elem) + return _escape_percents(str(elem)) if elem.name == 'a': try: @@ -87,9 +91,8 @@ cnts = list(elem.contents) if len(cnts) == 1: href_txt = cnts[0].string - href_parsed = urllib.parse.urlparse(href) if href_txt in href: - return href + return _escape_percents(href) a_txt = ''.join([_do_strip_html(c, ctx) for c in cnts])