diff --git a/tests/test_block.py b/tests/test_block.py index 0e6dc14f..c69105c2 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -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

New line

' + t = textile.Textile() + result = t.parse(input) + assert result == expect diff --git a/tests/test_urls.py b/tests/test_urls.py index 69bae4f5..0ae78e6e 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -46,6 +46,14 @@ def test_urls(): expect = '\t

A link that starts with an h is handled incorrectly.

' assert result == expect + result = t.parse('A link that starts with a space" raises":/test/ an exception.') + expect = '\t

A link that starts with a space” raises an exception.

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

A link that contains a\nnewline raises an exception.

' + assert result == expect + def test_rel_attribute(): t = Textile(rel='nofollow') result = t.parse('"$":http://domain.tld') diff --git a/textile/core.py b/textile/core.py index ce526946..018ccdb1 100644 --- a/textile/core.py +++ b/textile/core.py @@ -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: @@ -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) @@ -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, @@ -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 } diff --git a/textile/objects/block.py b/textile/objects/block.py index 3c7dc015..89e6b2e3 100644 --- a/textile/objects/block.py +++ b/textile/objects/block.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from __future__ import unicode_literals try: