Merge pull request #2115 from jvoisin/_update_content_regexp_simplification

Improve the regexp used in _update_content
This commit is contained in:
Justin Mayer 2017-04-20 12:18:11 -07:00 committed by GitHub
commit c2b2def1c8
2 changed files with 23 additions and 2 deletions

View file

@ -219,8 +219,8 @@ class Content(object):
instrasite_link_regex = self.settings['INTRASITE_LINK_REGEX']
regex = r"""
(?P<markup><\s*[^\>]* # match tag with all url-value attributes
(?:href|src|poster|data|cite|formaction|action)\s*=)
(?P<markup><[^\>]+ # match tag with all url-value attributes
(?:href|src|poster|data|cite|formaction|action)\s*=\s*)
(?P<quote>["\']) # require value to be quoted
(?P<path>{0}(?P<value>.*?)) # the url value

View file

@ -771,3 +771,24 @@ class TestStatic(LoggedTestCase):
count=1,
msg="Unable to find 'foo', skipping url replacement.",
level=logging.WARNING)
def test_index_link_syntax_with_spaces(self):
"""{index} link syntax triggers url replacement
with spaces around the equal sign."""
html = '<a href = "{index}">link</a>'
page = Page(
content=html,
metadata={'title': 'fakepage'},
settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html)
expected_html = ('<a href = "' +
'/'.join((self.settings['SITEURL'],
self.settings['INDEX_SAVE_AS'])) +
'">link</a>')
self.assertEqual(content, expected_html)