changeset 23:aa8f10e9ab55

Escape special characters.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 08 Sep 2019 16:07:24 -0700
parents 431cc200d526
children 2d064ee0c5e6
files silorider/format.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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])