Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastcore/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _to_xml(elm, lvl=0, indent=True, do_escape=True):

stag = tag
if attrs:
sattrs = ' '.join(_to_attr(k, v) for k, v in attrs.items() if v not in (False, None, '') and (k=='_' or k[-1]!='_'))
sattrs = ' '.join(_to_attr(k, v) for k, v in attrs.items() if v is not False and v is not None and (k=='_' or k[-1]!='_'))
if sattrs: stag += f' {sattrs}'

cltag = '' if is_void else f'</{tag}>'
Expand Down
6 changes: 4 additions & 2 deletions nbs/09_xml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"\n",
" stag = tag\n",
" if attrs:\n",
" sattrs = ' '.join(_to_attr(k, v) for k, v in attrs.items() if v not in (False, None, '') and (k=='_' or k[-1]!='_'))\n",
" sattrs = ' '.join(_to_attr(k, v) for k, v in attrs.items() if v is not False and v is not None and (k=='_' or k[-1]!='_'))\n",
" if sattrs: stag += f' {sattrs}'\n",
"\n",
" cltag = '' if is_void else f'</{tag}>'\n",
Expand Down Expand Up @@ -511,7 +511,9 @@
" \"<div>&lt;script&gt;alert('XSS')&lt;/script&gt;</div>\\n\")\n",
"test_eq(to_xml(Div(\"<script>alert('XSS')</script>\"), do_escape=False),\n",
" \"<div><script>alert('XSS')</script></div>\\n\")\n",
"test_eq(to_xml(Div(foo=False), indent=False), '<div></div>')"
"test_eq(to_xml(Div(foo=False), indent=False), '<div></div>')\n",
"test_eq(to_xml(Input(type=\"number\", min=0, max=100)), '<input type=\"number\" min=\"0\" max=\"100\">\\n')\n",
"test_eq(to_xml(Option(\"select a value\", value=\"\")), '<option value=\"\">select a value</option>')"
]
},
{
Expand Down