Terminate strings at NUL when recording states and events (#86687)
This commit is contained in:
parent
b9ffc67a44
commit
fea30c1ce9
6 changed files with 113 additions and 7 deletions
|
@ -10,6 +10,7 @@ from homeassistant import core
|
|||
from homeassistant.helpers.json import (
|
||||
ExtendedJSONEncoder,
|
||||
JSONEncoder,
|
||||
json_bytes_strip_null,
|
||||
json_dumps,
|
||||
json_dumps_sorted,
|
||||
)
|
||||
|
@ -118,3 +119,19 @@ def test_json_dumps_rgb_color_subclass():
|
|||
rgb = RGBColor(4, 2, 1)
|
||||
|
||||
assert json_dumps(rgb) == "[4,2,1]"
|
||||
|
||||
|
||||
def test_json_bytes_strip_null():
|
||||
"""Test stripping nul from strings."""
|
||||
|
||||
assert json_bytes_strip_null("\0") == b'""'
|
||||
assert json_bytes_strip_null("silly\0stuff") == b'"silly"'
|
||||
assert json_bytes_strip_null(["one", "two\0", "three"]) == b'["one","two","three"]'
|
||||
assert (
|
||||
json_bytes_strip_null({"k1": "one", "k2": "two\0", "k3": "three"})
|
||||
== b'{"k1":"one","k2":"two","k3":"three"}'
|
||||
)
|
||||
assert (
|
||||
json_bytes_strip_null([[{"k1": {"k2": ["silly\0stuff"]}}]])
|
||||
== b'[[{"k1":{"k2":["silly"]}}]]'
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue