diff --git a/python/test/test_scheme.py b/python/test/test_scheme.py index 374276a3..7c01e034 100644 --- a/python/test/test_scheme.py +++ b/python/test/test_scheme.py @@ -503,11 +503,16 @@ def test_bytes(): m.f0 = 'abc' with pytest.raises(ValueError): - m.f0 = b'abc' + m.f1 = 'abc' + + m.f2 = 'abc' with pytest.raises(TypeError): m.f0 = 1 + with pytest.raises(TypeError): + m.f1 = 1 + def test_time_point(): scheme = S.Scheme("""yamls:// - name: msg diff --git a/python/tll/scheme.pyx b/python/tll/scheme.pyx index 59402580..c4f5e37a 100644 --- a/python/tll/scheme.pyx +++ b/python/tll/scheme.pyx @@ -742,7 +742,11 @@ cdef class FFixedString(FBase): cdef pack(FFixedString self, v, dest, tail, int tail_offset): return pack_bytes(v, dest, tail, tail_offset) cdef unpack(FFixedString self, src): return unpack_str(src[:self.size]) - cdef convert(FFixedString self, v): return convert_str(v) + cdef convert(FFixedString self, v): + v = convert_str(v) + if len(v) > self.size: + raise ValueError(f"String too long: {len(v)} > {self.size}") + return v cdef from_string(FFixedString self, str s): return s _SUBTYPES[(Type.Bytes, SubType.ByteString)] = FFixedString