|
30 | 30 | import markdown
|
31 | 31 | import warnings
|
32 | 32 | from markdown.__main__ import parse_options
|
| 33 | +from markdown import inlinepatterns |
33 | 34 | from logging import DEBUG, WARNING, CRITICAL
|
34 | 35 | import yaml
|
35 | 36 | import tempfile
|
@@ -664,8 +665,8 @@ class testAtomicString(unittest.TestCase):
|
664 | 665 | """ Test that `AtomicStrings` are honored (not parsed). """
|
665 | 666 |
|
666 | 667 | def setUp(self):
|
667 |
| - md = markdown.Markdown() |
668 |
| - self.inlineprocessor = md.treeprocessors['inline'] |
| 668 | + self.md = markdown.Markdown() |
| 669 | + self.inlineprocessor = self.md.treeprocessors['inline'] |
669 | 670 |
|
670 | 671 | def testString(self):
|
671 | 672 | """ Test that a regular string is parsed. """
|
@@ -710,6 +711,26 @@ def testNestedAtomicString(self):
|
710 | 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 | 735 | class TestConfigParsing(unittest.TestCase):
|
715 | 736 | def assertParses(self, value, result):
|
|
0 commit comments