File tree Expand file tree Collapse file tree 4 files changed +30
-10
lines changed Expand file tree Collapse file tree 4 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -172,18 +172,20 @@ def _render(
172172 else :
173173 opening += ">"
174174
175- if not len (self .children ):
175+ # Render children
176+ indent_increase = options .indent if options .spacing == "\n " else ""
177+ children = util .render_children (
178+ self .children ,
179+ self ._escape_children (),
180+ "" if indent_increase is None else indent + indent_increase ,
181+ options ,
182+ )
183+
184+ # If rendering the children produced no output
185+ if not len (children ):
176186 opening += f"</{ self ._get_tag_name ()} >"
177187 return [opening ]
178188 else :
179- indent_increase = options .indent if options .spacing == "\n " else ""
180- # Children
181- children = util .render_children (
182- self .children ,
183- self ._escape_children (),
184- "" if indent_increase is None else indent + indent_increase ,
185- options ,
186- )
187189 closing = f"</{ self ._get_tag_name ()} >"
188190 if options .spacing == "\n " :
189191 return [
Original file line number Diff line number Diff line change 11[project ]
22name = " pyhtml-enhanced"
3- version = " 2.2.3 "
3+ version = " 2.2.4 "
44description = " A library for building HTML documents with a simple and learnable syntax"
55readme = " README.md"
66license = " MIT"
Original file line number Diff line number Diff line change @@ -343,3 +343,12 @@ def test_whitespace_sensitive_with_attrs():
343343 Do whitespace-sensitive tags render properly when they have attributes?
344344 """
345345 assert str (pre (test = "test" )("hi" )) == '<pre test="test">hi</pre>'
346+
347+
348+ def test_render_ele_with_empty_str ():
349+ """
350+ Rendering an element with an empty string used to cause a crash. Add a
351+ test so we avoid it.
352+ """
353+ doc = body ("" )
354+ assert str (doc ) == "<body></body>"
Original file line number Diff line number Diff line change @@ -161,3 +161,12 @@ def test_paragraphs_render_in_body():
161161 "</body>" ,
162162 ]
163163 )
164+
165+
166+ def test_render_paragraph_with_empty_str ():
167+ """
168+ Rendering a paragraph with an empty string used to cause a crash. Add a
169+ test so we avoid it.
170+ """
171+ doc = p .p ("" )
172+ assert str (doc ) == "<p></p>"
You can’t perform that action at this time.
0 commit comments