From 793fdb53172ac8fe0c104b52a4b11c04b2e49a93 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 25 Nov 2020 16:10:33 +0100 Subject: [PATCH] Tweak template digit detection (#43621) --- homeassistant/helpers/template.py | 2 +- tests/helpers/test_template.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 09a9170c79a..fb3e6ba40b5 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -50,7 +50,7 @@ _ENVIRONMENT = "template.environment" _RE_JINJA_DELIMITERS = re.compile(r"\{%|\{\{|\{#") # Match "simple" ints and floats. -1.0, 1, +5, 5.0 -_IS_NUMERIC = re.compile(r"^[+-]?\d*(?:\.\d*)?$") +_IS_NUMERIC = re.compile(r"^[+-]?(?!0\d)\d*(?:\.\d*)?$") _RESERVED_NAMES = {"contextfunction", "evalcontextfunction", "environmentfunction"} diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 53186ed35a1..c8a8bc0710c 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -2421,11 +2421,17 @@ async def test_parse_result(hass): ("1e+100", "1e+100"), ("0xface", "0xface"), ("123", 123), + ("10", 10), ("123.0", 123.0), (".5", 0.5), + ("0.5", 0.5), ("-1", -1), ("-1.0", -1.0), ("+1", 1), ("5.", 5.0), + ("123_123_123", "123_123_123"), + # ("+48100200300", "+48100200300"), # phone number + ("010", "010"), + ("0011101.00100001010001", "0011101.00100001010001"), ): assert template.Template(tpl, hass).async_render() == result