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(
172
172
else :
173
173
opening += ">"
174
174
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 ):
176
186
opening += f"</{ self ._get_tag_name ()} >"
177
187
return [opening ]
178
188
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
- )
187
189
closing = f"</{ self ._get_tag_name ()} >"
188
190
if options .spacing == "\n " :
189
191
return [
Original file line number Diff line number Diff line change 1
1
[project ]
2
2
name = " pyhtml-enhanced"
3
- version = " 2.2.3 "
3
+ version = " 2.2.4 "
4
4
description = " A library for building HTML documents with a simple and learnable syntax"
5
5
readme = " README.md"
6
6
license = " MIT"
Original file line number Diff line number Diff line change @@ -343,3 +343,12 @@ def test_whitespace_sensitive_with_attrs():
343
343
Do whitespace-sensitive tags render properly when they have attributes?
344
344
"""
345
345
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():
161
161
"</body>" ,
162
162
]
163
163
)
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