diff --git a/supervisor/utils/gdbus.py b/supervisor/utils/gdbus.py index 1abecae99..643571cc3 100644 --- a/supervisor/utils/gdbus.py +++ b/supervisor/utils/gdbus.py @@ -34,7 +34,7 @@ RE_GVARIANT_STRING: re.Pattern[Any] = re.compile( r"(?<=(?: |{|\[|\(|<))'(.*?)'(?=(?:|]|}|,|\)|>))" ) RE_GVARIANT_BINARY: re.Pattern[Any] = re.compile( - r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|\[byte (.*?)\]" + r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|\[byte (.*?)\]|\[(0x[0-9A-Za-z]{2}.*?)\]" ) RE_GVARIANT_BINARY_STRING: re.Pattern[Any] = re.compile( r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|?" @@ -45,7 +45,7 @@ RE_GVARIANT_TUPLE_C: re.Pattern[Any] = re.compile( ) RE_BIN_STRING_OCT: re.Pattern[Any] = re.compile(r"\\\\(\d{3})") -RE_BIN_STRING_HEX: re.Pattern[Any] = re.compile(r"\\\\x(\d{2})") +RE_BIN_STRING_HEX: re.Pattern[Any] = re.compile(r"\\\\x([0-9A-Za-z]{2})") RE_MONITOR_OUTPUT: re.Pattern[Any] = re.compile(r".+?: (?P[^ ].+) (?P.*)") @@ -142,7 +142,9 @@ class DBus: # Handle Bytes json_raw = RE_GVARIANT_BINARY.sub( - lambda x: x.group(0) if not x.group(1) else _convert_bytes(x.group(1)), + lambda x: x.group(0) + if not (x.group(1) or x.group(2)) + else _convert_bytes(x.group(1) or x.group(2)), json_raw, ) json_raw = RE_GVARIANT_BINARY_STRING.sub( diff --git a/tests/utils/test_gvariant_parser.py b/tests/utils/test_gvariant_parser.py index a04087fe5..3b1ac4a8c 100644 --- a/tests/utils/test_gvariant_parser.py +++ b/tests/utils/test_gvariant_parser.py @@ -454,7 +454,7 @@ def test_networkmanager_binary_string_data(): def test_v6(): """Test IPv6 Property.""" - raw = "({'addresses': <[([byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10], uint32 64, [byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])]>, 'dns': <[[byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05]]>})" + raw = "({'addresses': <[([byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10], uint32 64, [byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])]>, 'dns': <[[byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05], [0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05]]>})" data = DBus.parse_gvariant(raw) @@ -467,6 +467,9 @@ def test_v6(): [32, 1, 4, 112, 121, 45, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], ] ], - "dns": [[32, 1, 4, 112, 121, 45, 0, 1, 0, 18, 0, 0, 0, 0, 0, 5]], + "dns": [ + [32, 1, 4, 112, 121, 45, 0, 1, 0, 18, 0, 0, 0, 0, 0, 5], + [32, 1, 4, 112, 121, 45, 0, 1, 0, 18, 0, 0, 0, 0, 0, 5], + ], } ]