Skip to content

IndexError and TypeError while markdown to html conversion #966

@Arjunsankarlal

Description

@Arjunsankarlal

When I try to convert a small markdown content into HTML with the below code,

html = MD.reset().convert(para)

it works without any problem. But when I make swarm multiple concurrent requests with that content I get the following three types of error which occurs randomly. Most of the time a single type of error would occur.

File "/Users/arjun/converter/util.py", line 101, in markdown_to_text
html = MD.reset().convert(para)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/core.py", line 295, in convert
output = pp.run(output)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/postprocessors.py", line 75, in run
html = self.md.htmlStash.rawHtmlBlocks[i]
IndexError: list index out of range```

File "/Users/arjun/converter/util.py", line 101, in markdown_to_text
html = MD.reset().convert(para)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/core.py", line 272, in convert
newRoot = treeprocessor.run(root)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/treeprocessors.py", line 378, in run
self.ancestors.pop()
IndexError: pop from empty list

File "/Users/arjun/converter/util.py", line 101, in markdown_to_text
html = MD.reset().convert(para)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/core.py", line 272, in convert
newRoot = treeprocessor.run(root)
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/treeprocessors.py", line 372, in run
self.__handleInline(text), child
File "/Users/arjun/environments/mdtest/lib/python3.6/site-packages/markdown/treeprocessors.py", line 215, in __processPlaceholders
for child in [node] + list(node):
TypeError: 'NoneType' object is not iterable

And the dummy content I passed as input is,

**To edit a record:**

  1. Click the **Red** Button.

  2. In the _main_ page, click the **Home** tab in the lower-left corner.

  3. In the _Home_ page, select an record to view its details.

  4. In the _details_ page, click the **Save& Data** icon ( ![](https://www.abc.com/data?id=1234567&mode=inline&blockId=6wqjmd23e123456789009876543){: style="width: 13px; vertical-align: sub; max-width: 100%" height width } ) from the floating widgets on the left of the screen.

  5. Under _Save & Data Information_ section, click **New Data**.

It was happening randomly for different data. So reproduce the issue with a small content I took this. Generally when it happened the number of requests were low. But to reproduce the issue for this content I had to increase the request count as 200req/sec, and I could reproduce it after 20000, successfully completed requests

My suggestions are (based on the issue order)

  1. Iterating based on the length of self.md.htmlStash.rawHtmlBlocks[i]
  2. Checking the length before popping
  3. Adding null checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions