|
26 | 26 |
|
27 | 27 | logger = logging.getLogger(__name__) |
28 | 28 |
|
| 29 | +try: |
| 30 | + import html |
| 31 | +except ImportError: |
| 32 | + # html.escape()/html.unescape() is since Python 3.2, do this for py2.7 |
| 33 | + # https://wiki.python.org/moin/EscapingHtml |
| 34 | + from xml.sax.saxutils import escape, unescape |
| 35 | + |
| 36 | + class html(object): |
| 37 | + _html_escape_table = {'"': """, |
| 38 | + "'": "'"} |
| 39 | + _html_unescape_table = {'"': '"', |
| 40 | + ''': "'"} |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def escape(cls, v): return escape(v, cls._html_escape_table) |
| 44 | + |
| 45 | + @classmethod |
| 46 | + def unescape(cls, v): return unescape(v, cls._html_unescape_table) |
| 47 | + |
29 | 48 |
|
30 | 49 | @python_2_unicode_compatible |
31 | 50 | class Content(object): |
@@ -230,9 +249,9 @@ def get_url_setting(self, key): |
230 | 249 |
|
231 | 250 | def _link_replacer(self, siteurl, m): |
232 | 251 | what = m.group('what') |
233 | | - value = urlparse(m.group('value')) |
| 252 | + value = urlparse(html.unescape(m.group('value'))) |
234 | 253 | path = value.path |
235 | | - origin = m.group('path') |
| 254 | + origin = html.unescape(m.group('path')) |
236 | 255 |
|
237 | 256 | # XXX Put this in a different location. |
238 | 257 | if what in {'filename', 'attach'}: |
@@ -285,7 +304,7 @@ def _link_replacer(self, siteurl, m): |
285 | 304 | # keep all other parts, such as query, fragment, etc. |
286 | 305 | parts = list(value) |
287 | 306 | parts[2] = origin |
288 | | - origin = urlunparse(parts) |
| 307 | + origin = html.escape(urlunparse(parts)) |
289 | 308 |
|
290 | 309 | return ''.join((m.group('markup'), m.group('quote'), origin, |
291 | 310 | m.group('quote'))) |
|
0 commit comments