Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various exceptions that appeared when moving from 2.2.2 to 2.3.11 #44

Merged
merged 9 commits into from
Jun 3, 2017
7 changes: 7 additions & 0 deletions tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ def test_blockcode_in_README():
with open('tests/fixtures/README.txt') as f:
expect = ''.join(f.readlines())
assert result == expect

def test_blockcode_comment():
input = '###.. block comment\nanother line\n\np. New line'
expect = '\t<p>New line</p>'
t = textile.Textile()
result = t.parse(input)
assert result == expect
8 changes: 8 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def test_urls():
expect = '\t<p>A link that starts with an h is <a href="/test/">handled</a> incorrectly.</p>'
assert result == expect

result = t.parse('A link that starts with a space" raises":/test/ an exception.')
expect = '\t<p><a href="/test/">A link that starts with a space&#8221; raises</a> an exception.</p>'
assert result == expect

result = t.parse('A link that "contains a\nnewline":/test/ raises an exception.')
expect = '\t<p>A link that <a href="/test/">contains a\nnewline</a> raises an exception.</p>'
assert result == expect

def test_rel_attribute():
t = Textile(rel='nofollow')
result = t.parse('"$":http://domain.tld')
Expand Down
15 changes: 9 additions & 6 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def block(self, text):
else:
# if we're inside an extended block, add the text from the
# previous extension to the front
if ext:
if ext and out:
line = '{0}\n\n{1}'.format(out.pop(), line)
whitespace = ' \t\n\r\f\v'
if ext or not line[0] in whitespace:
Expand Down Expand Up @@ -494,7 +494,7 @@ def block(self, text):
cite = ''
graf = ''

if ext:
if ext and out:
out.append(generate_tag(block.outer_tag, out.pop(),
block.outer_atts))
return '\n\n'.join(out)
Expand Down Expand Up @@ -672,7 +672,10 @@ def markStartOfLinks(self, text):
balanced = balanced - 1
if re.search(r'\S$', possibility, flags=re.U): # pragma: no branch
balanced = balanced + 1
possibility = possible_start_quotes.pop()
try:
possibility = possible_start_quotes.pop()
except IndexError:
break
else:
# If quotes occur next to each other, we get zero
# length strings. eg. ...""Open the door,
Expand Down Expand Up @@ -756,9 +759,9 @@ def fLink(self, m):
$'''.format(cls_re_s, regex_snippets['space']), inner,
flags=re.X | re.U)

atts = m.group('atts') or ''
text = m.group('text') or '' or inner
title = m.group('title') or ''
atts = (m and m.group('atts')) or ''
text = (m and m.group('text')) or inner
title = (m and m.group('title')) or ''

pop, tight = '', ''
counts = { '[': None, ']': url.count(']'), '(': None, ')': None }
Expand Down
1 change: 1 addition & 0 deletions textile/objects/block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

try:
Expand Down