From 5b8ca619d3705cf30c205a883f2fb7158a2786b5 Mon Sep 17 00:00:00 2001 From: Erik Gaasedelen Date: Tue, 2 Dec 2025 22:10:57 -0800 Subject: [PATCH] add tests --- fastcore/xml.py | 2 +- nbs/09_xml.ipynb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fastcore/xml.py b/fastcore/xml.py index b1e3946f..31cf4967 100644 --- a/fastcore/xml.py +++ b/fastcore/xml.py @@ -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'' diff --git a/nbs/09_xml.ipynb b/nbs/09_xml.ipynb index bd16c3f1..02aed112 100644 --- a/nbs/09_xml.ipynb +++ b/nbs/09_xml.ipynb @@ -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''\n", @@ -511,7 +511,9 @@ " \"
<script>alert('XSS')</script>
\\n\")\n", "test_eq(to_xml(Div(\"\"), do_escape=False),\n", " \"
\\n\")\n", - "test_eq(to_xml(Div(foo=False), indent=False), '
')" + "test_eq(to_xml(Div(foo=False), indent=False), '
')\n", + "test_eq(to_xml(Input(type=\"number\", min=0, max=100)), '\\n')\n", + "test_eq(to_xml(Option(\"select a value\", value=\"\")), '')" ] }, {