Skip to content

Commit da00f08

Browse files
authored
Merge pull request #44 from adam-iris/regressions
Various exceptions that appeared when moving from 2.2.2 to 2.3.11
2 parents a8a6a02 + deca51e commit da00f08

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

tests/test_block.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ def test_blockcode_in_README():
6262
with open('tests/fixtures/README.txt') as f:
6363
expect = ''.join(f.readlines())
6464
assert result == expect
65+
66+
def test_blockcode_comment():
67+
input = '###.. block comment\nanother line\n\np. New line'
68+
expect = '\t<p>New line</p>'
69+
t = textile.Textile()
70+
result = t.parse(input)
71+
assert result == expect

tests/test_urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def test_urls():
4646
expect = '\t<p>A link that starts with an h is <a href="/test/">handled</a> incorrectly.</p>'
4747
assert result == expect
4848

49+
result = t.parse('A link that starts with a space" raises":/test/ an exception.')
50+
expect = '\t<p><a href="/test/">A link that starts with a space&#8221; raises</a> an exception.</p>'
51+
assert result == expect
52+
53+
result = t.parse('A link that "contains a\nnewline":/test/ raises an exception.')
54+
expect = '\t<p>A link that <a href="/test/">contains a\nnewline</a> raises an exception.</p>'
55+
assert result == expect
56+
4957
def test_rel_attribute():
5058
t = Textile(rel='nofollow')
5159
result = t.parse('"$":http://domain.tld')

textile/core.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def block(self, text):
465465
else:
466466
# if we're inside an extended block, add the text from the
467467
# previous extension to the front
468-
if ext:
468+
if ext and out:
469469
line = '{0}\n\n{1}'.format(out.pop(), line)
470470
whitespace = ' \t\n\r\f\v'
471471
if ext or not line[0] in whitespace:
@@ -494,7 +494,7 @@ def block(self, text):
494494
cite = ''
495495
graf = ''
496496

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

759-
atts = m.group('atts') or ''
760-
text = m.group('text') or '' or inner
761-
title = m.group('title') or ''
762+
atts = (m and m.group('atts')) or ''
763+
text = (m and m.group('text')) or inner
764+
title = (m and m.group('title')) or ''
762765

763766
pop, tight = '', ''
764767
counts = { '[': None, ']': url.count(']'), '(': None, ')': None }

textile/objects/block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
from __future__ import unicode_literals
23

34
try:

0 commit comments

Comments
 (0)