Fix edge-case crash in InlineProcessor by oprypin · Pull Request #1406 · Python-Markdown/markdown (original) (raw)
If an inlineprocessor returns an AtomicString (even though that is pointless, a plain string is atomic in that context), there can be an exception in 2 separate places. The added test case was crashing before this change.
File "tests/test_apis.py", line 722, in testInlineProcessorDoesntCrashWithAtomicString
new = self.inlineprocessor.run(tree)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "markdown/treeprocessors.py", line 384, in run
lst = self.__processPlaceholders(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "markdown/treeprocessors.py", line 223, in __processPlaceholders
if child.tail:
^^^^^^^^^^
AttributeError: 'AtomicString' object has no attribute 'tail'
File "tests/test_apis.py", line 722, in testInlineProcessorDoesntCrashWithAtomicString
new = self.inlineprocessor.run(tree)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "markdown/treeprocessors.py", line 387, in run
self.__handleInline(text), child
^^^^^^^^^^^^^^^^^^^^^^^^^
File "markdown/treeprocessors.py", line 136, in __handleInline
data, matched, startIndex = self.__applyPattern(
^^^^^^^^^^^^^^^^^^^^
File "markdown/treeprocessors.py", line 310, in __applyPattern
if not isinstance(node.text, util.AtomicString):
^^^^^^^^^
AttributeError: 'AtomicString' object has no attribute 'text'