Relax the icon validator to allow non-mdi icons (#2764)

This commit is contained in:
Paul Monigatti 2021-11-23 21:21:14 +13:00 committed by GitHub
parent 710096b1c6
commit 05fe5db030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -296,9 +296,11 @@ def icon(value):
value = string_strict(value) value = string_strict(value)
if not value: if not value:
return value return value
if value.startswith("mdi:"): if re.match("^[\\w\\-]+:[\\w\\-]+$", value):
return value return value
raise Invalid('Icons should start with prefix "mdi:"') raise Invalid(
'Icons must match the format "[icon pack]:[icon]", e.g. "mdi:home-assistant"'
)
def boolean(value): def boolean(value):

View file

@ -66,7 +66,7 @@ def test_string_string__invalid(value):
config_validation.string_strict(value) config_validation.string_strict(value)
@given(builds(lambda v: "mdi:" + v, text())) @given(builds(lambda v: "mdi:" + v, text(alphabet=string.ascii_letters + string.digits + "-_", min_size=1, max_size=20)))
@example("") @example("")
def test_icon__valid(value): def test_icon__valid(value):
actual = config_validation.icon(value) actual = config_validation.icon(value)
@ -75,7 +75,7 @@ def test_icon__valid(value):
def test_icon__invalid(): def test_icon__invalid():
with pytest.raises(Invalid, match="Icons should start with prefix"): with pytest.raises(Invalid, match="Icons must match the format "):
config_validation.icon("foo") config_validation.icon("foo")