|
30 | import markdown
| 30 | import markdown
|
31 | import warnings
| 31 | import warnings
|
32 | from markdown.__main__ import parse_options
| 32 | from markdown.__main__ import parse_options
|
| | 33 | +from markdown import inlinepatterns |
33 | from logging import DEBUG, WARNING, CRITICAL
| 34 | from logging import DEBUG, WARNING, CRITICAL
|
34 | import yaml
| 35 | import yaml
|
35 | import tempfile
| 36 | import tempfile
|
@@ -664,8 +665,8 @@ class testAtomicString(unittest.TestCase):
|
664 | """ Test that `AtomicStrings` are honored (not parsed). """
| 665 | """ Test that `AtomicStrings` are honored (not parsed). """
|
665 |
| 666 |
|
666 | def setUp(self):
| 667 | def setUp(self):
|
667 | - md = markdown.Markdown() | 668 | + self.md = markdown.Markdown() |
668 | - self.inlineprocessor = md.treeprocessors['inline'] | 669 | + self.inlineprocessor = self.md.treeprocessors['inline'] |
669 |
| 670 |
|
670 | def testString(self):
| 671 | def testString(self):
|
671 | """ Test that a regular string is parsed. """
| 672 | """ Test that a regular string is parsed. """
|
@@ -710,6 +711,26 @@ def testNestedAtomicString(self):
|
710 | '*to*</span> *test*</span> *with*</p></div>'
| 711 | '*to*</span> *test*</span> *with*</p></div>'
|
711 | )
| 712 | )
|
712 |
| 713 |
|
| | 714 | + def testInlineProcessorDoesntCrashWithWrongAtomicString(self): |
| | 715 | + """ Test that an `AtomicString` returned from a Pattern doesn't cause a crash. """ |
| | 716 | + tree = etree.Element('div') |
| | 717 | + p = etree.SubElement(tree, 'p') |
| | 718 | + p.text = 'a marker c' |
| | 719 | + self.md.inlinePatterns.register( |
| | 720 | + _InlineProcessorThatReturnsAtomicString(r'marker', self.md), 'test', 100 |
| | 721 | + ) |
| | 722 | + new = self.inlineprocessor.run(tree) |
| | 723 | + self.assertEqual( |
| | 724 | + markdown.serializers.to_html_string(new), |
| | 725 | + '<div><p>a <b>atomic</b> c</p></div>' |
| | 726 | + ) |
| | 727 | + |
| | 728 | + |
| | 729 | +class _InlineProcessorThatReturnsAtomicString(inlinepatterns.InlineProcessor): |
| | 730 | + """ Return a simple text of `group(1)` of a Pattern. """ |
| | 731 | + def handleMatch(self, m, data): |
| | 732 | + return markdown.util.AtomicString('<b>atomic</b>'), m.start(0), m.end(0) |
| | 733 | + |
713 |
| 734 |
|
714 | class TestConfigParsing(unittest.TestCase):
| 735 | class TestConfigParsing(unittest.TestCase):
|
715 | def assertParses(self, value, result):
| 736 | def assertParses(self, value, result):
|
|
0 commit comments