Skip to content

Commit

Permalink
Fix HTML attribute regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jan 14, 2017
1 parent 1e551e1 commit f7b5239
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
]
_pre_tags = ['pre', 'script', 'style']
_valid_end = r'(?!:/|[^\w\s@]*@)\b'
_valid_attr = r'''\s*[a-zA-Z\-](?:\=(?:"[^"]*"|'[^']*'|\d+))*'''
_valid_attr = r'''\s*[a-zA-Z\-](?:\=(?:"[^"]+"|'[^']+'|[^\s'">]+))?'''
_block_tag = r'(?!(?:%s)\b)\w+%s' % ('|'.join(_inline_tags), _valid_end)
_scheme_blacklist = ('javascript:', 'vbscript:')

Expand Down
22 changes: 22 additions & 0 deletions tests/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def test_parse_inline_html():
)
assert '<span><strong>' in ret

ret = mistune.markdown(
'<span id="foo">**foo**</span>', parse_inline_html=True, escape=False
)
assert '<span id="foo"><strong>' in ret

ret = mistune.markdown(
'<span id=foo>**foo**</span>', parse_inline_html=True, escape=False
)
assert '<span id=foo><strong>' in ret

ret = mistune.markdown(
'<a>http://lepture.com</a>', parse_inline_html=True, escape=False
)
Expand All @@ -81,11 +91,23 @@ def test_block_html():
)
assert '<div ></div>' in ret


def test_parse_block_html():
ret = mistune.markdown(
'<div>**foo**</div>', parse_block_html=True, escape=False
)
assert '<div><strong>' in ret

ret = mistune.markdown(
'<div id="foo">**foo**</div>', parse_block_html=True, escape=False
)
assert '<div id="foo"><strong>' in ret

ret = mistune.markdown(
'<div id=foo>**foo**</div>', parse_block_html=True, escape=False
)
assert '<div id=foo><strong>' in ret

ret = mistune.markdown(
'<span>**foo**</span>', parse_block_html=True, escape=False
)
Expand Down

0 comments on commit f7b5239

Please sign in to comment.