Skip to content

Commit

Permalink
Fix link replacer to properly escape special HTML characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Dec 10, 2017
1 parent 5450d8a commit 33ae2ac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import print_function, unicode_literals

import copy
import html
import locale
import logging
import os
Expand Down Expand Up @@ -230,9 +231,9 @@ def get_url_setting(self, key):

def _link_replacer(self, siteurl, m):
what = m.group('what')
value = urlparse(m.group('value'))
value = urlparse(html.unescape(m.group('value')))
path = value.path
origin = m.group('path')
origin = html.unescape(m.group('path'))

# XXX Put this in a different location.
if what in {'filename', 'attach'}:
Expand Down Expand Up @@ -285,7 +286,7 @@ def _link_replacer(self, siteurl, m):
# keep all other parts, such as query, fragment, etc.
parts = list(value)
parts[2] = origin
origin = urlunparse(parts)
origin = html.escape(urlunparse(parts))

return ''.join((m.group('markup'), m.group('quote'), origin,
m.group('quote')))
Expand Down

0 comments on commit 33ae2ac

Please sign in to comment.