Skip to content

Commit

Permalink
Merge pull request #38 from elupus/context_invalid
Browse files Browse the repository at this point in the history
Ignore invalid json "Context Service not started"
  • Loading branch information
elupus authored May 21, 2024
2 parents 7bdfe0a + f7a08ba commit 21caf6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions haphilipsjs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
HTTP_PORT = 1925
HTTPS_PORT = 1926
MAXIMUM_ITEMS_IN_REQUEST = 50

IGNORED_JSON_RESPONSES = {"", "Context Service not started", "}"}

def hmac_signature(key: bytes, timestamp: str, data: str):
"""Calculate a timestamped signature."""
Expand Down Expand Up @@ -101,7 +101,7 @@ def cbc_encode(key: bytes, data: str):


def decode_xtv_json(text: str):
if text == "" or text == "}":
if text in IGNORED_JSON_RESPONSES:
LOG.debug("Ignoring invalid json %s", text)
return {}

Expand Down
1 change: 1 addition & 0 deletions tests/test_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def mock_strings(request: StringsRequest, response: Strings):
async def test_buggy_json():
assert haphilipsjs.decode_xtv_json("") == {}
assert haphilipsjs.decode_xtv_json("}") == {}
assert haphilipsjs.decode_xtv_json("Context Service not started") == {}
assert haphilipsjs.decode_xtv_json('{,"a":{}}') == {"a": {}}
assert haphilipsjs.decode_xtv_json('{"a":{},}') == {"a": {}}
assert haphilipsjs.decode_xtv_json('{"a":{},,,"b":{}}') == {"a": {}, "b": {}}
Expand Down

0 comments on commit 21caf6f

Please sign in to comment.