Skip to content

RecursionError on deeply nested HTML (about 330 levels), separate from the cyclic-tree case in #256 #276

Description

@HardMax71

process_element / process_tag recurse three Python frames per nesting level (markdownify/__init__.py 228-232, 234, 287-288 on develop), so a plain acyclic tree hits the default recursion limit at around 330 levels. Real mail clients produce this: Outlook wraps quoted replies in empty <div>s and a long thread easily passes that depth.

deep div nesting depth=300: OK len=5
deep div nesting depth=330: RecursionError (maximum recursion depth exceeded)
deep div nesting depth=500: RecursionError (maximum recursion depth exceeded)
cyclic soup (p contains its ancestor div): RecursionError (maximum recursion depth exceeded)

Repro on 1.2.3: https://gist.github.com/HardMax71/bbfc6f70bab3ec6417d4f80324f40387. The one-liner is markdownify("<div>" * 330 + "x" + "</div>" * 330).

I applied the hunk from #274 to 1.2.3 to check: the cyclic case passes, the depth case still fails. So #256/#274 cover cycles and this needs its own guard. Cheapest fix: thread a depth counter through process_tag and past a max_depth option fall back to node.get_text(); a full fix walks node.descendants without recursion.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions