From a04f5137fd5af288b82baaa8132d5e0164a8c9e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Wed, 26 May 2021 21:53:45 +0200
Subject: [PATCH] 99% coverage

---
 minijson.pyx           | 12 +++---------
 tests/test_minijson.py |  7 -------
 2 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/minijson.pyx b/minijson.pyx
index 6dc239e..0ad344f 100644
--- a/minijson.pyx
+++ b/minijson.pyx
@@ -318,9 +318,7 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
         return 1
     elif isinstance(data, str):
         length = len(data)
-        if length < 0:
-            raise EncodingError('Invalid length!')
-        elif length < 128:
+        if length < 128:
             cio.write(bytearray([0x80 | length]))
             cio.write(data.encode('utf-8'))
             return 1+length
@@ -333,13 +331,11 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
             cio.write(STRUCT_H.pack(length))
             cio.write(data.encode('utf-8'))
             return 3+length
-        elif length <= 0xFFFFFFFF:
+        else:       # Python strings cannot grow past 0xFFFFFFFF characters
             cio.write(b'\x0E')
             cio.write(STRUCT_L.pack(length))
             cio.write(data.encode('utf-8'))
             return 5+length
-        else:
-            raise EncodingError('String is too long!')
     elif isinstance(data, int):
         if -128 <= data <= 127: # signed char, type 3
             cio.write(b'\x03')
@@ -439,12 +435,10 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
                 cio.write(b'\x15')
                 cio.write(STRUCT_H.pack(length))
                 offset = 3
-            elif length <= 0xFFFFFFFF:
+            else:       # Python objects cannot grow to have more than 0xFFFFFFFF members
                 cio.write(b'\x13')
                 cio.write(STRUCT_L.pack(length))
                 offset = 5
-            else:
-                raise EncodingError('Too long of a sdict!')
 
             for key, value in data.items():
                 offset += dump(key, cio)
diff --git a/tests/test_minijson.py b/tests/test_minijson.py
index 0a312c3..4fb9732 100644
--- a/tests/test_minijson.py
+++ b/tests/test_minijson.py
@@ -50,13 +50,6 @@ class TestMiniJSON(unittest.TestCase):
         self.assertSameAfterDumpsAndLoads(c)
         self.assertSameAfterDumpsAndLoads(d)
 
-    def test_too_long_string(self):
-        class Test(str):
-            def __len__(self):
-                return 0x1FFFFFFFF
-
-        self.assertRaises(EncodingError, lambda: dumps(Test()))
-
     def test_lists(self):
         a = [None]*4
         self.assertSameAfterDumpsAndLoads(a)
-- 
GitLab