diff --git a/pysubs2/jsonformat.py b/pysubs2/jsonformat.py index df838ee..37ded3e 100644 --- a/pysubs2/jsonformat.py +++ b/pysubs2/jsonformat.py @@ -24,7 +24,7 @@ class JSONFormat(FormatBase): @classmethod def guess_format(cls, text): """See :meth:`pysubs2.formats.FormatBase.guess_format()`""" - if text.startswith("{\""): + if text.startswith("{\"") and "\"info:\"" in text: return "json" @classmethod diff --git a/tests/test_json.py b/tests/test_json.py index 74278e5..11a7444 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -1,4 +1,7 @@ -from pysubs2 import SSAFile, SSAEvent, SSAStyle, Color +import pytest +import os.path as op +from pysubs2 import SSAFile, SSAEvent, SSAStyle, Color, FormatAutodetectionError +import tempfile def test_write_read(): subs = SSAFile() @@ -15,3 +18,13 @@ def test_write_read(): subs2 = SSAFile.from_string(json_text, "json") assert subs2.equals(subs) + + +def test_read_unsupported_json_issue_85(): + with tempfile.TemporaryDirectory() as temp_dir: + path = op.join(temp_dir, "test.atpj") + with open(path, "w") as fp: + print("""{"some data": [1,2,3]}""", file=fp) + + with pytest.raises(FormatAutodetectionError): + SSAFile.load(path)