Well, to be clearer, while it always crashes it only *sometimes* creates invalid markup. I ran into the bug because I am using a templating library that recursively copies child elements into (a copy of) the parent element. The bug was triggered when the templating engine was copying a template containing
. The first child the templating engine tried to copy into a new table node was the textnode consisting of just whitespace before the tbody. Creating (temporarily) <table>..whitespace..</table> is, I think, a plausible step in building a table. If jq continues to throw this error, then it becomes the responsibility of the template engine to check for and skip inserting whitespace, which just doesn't seem like a job it should have to do given that it is building valid html.