Repair errors surfaced by the new tests

This commit is contained in:
Tony Garnock-Jones 2023-10-29 19:27:29 +01:00
parent a14b2d49b7
commit c30073c3f9
2 changed files with 11 additions and 1 deletions

View File

@ -282,6 +282,14 @@ class Parser(TextCodec):
return tuple(vs) return tuple(vs)
vs.append(self.next()) vs.append(self.next())
def read_set(self):
items = self.upto('}')
s = set()
for i in items:
if i in s: raise DecodeError('Duplicate value in set: ' + repr(i))
s.add(i)
return frozenset(s)
def read_dictionary(self): def read_dictionary(self):
acc = [] acc = []
while True: while True:
@ -344,7 +352,7 @@ class Parser(TextCodec):
c = self.nextchar() c = self.nextchar()
if c == 'f': return self.wrap(False) if c == 'f': return self.wrap(False)
if c == 't': return self.wrap(True) if c == 't': return self.wrap(True)
if c == '{': return self.wrap(frozenset(self.upto('}'))) if c == '{': return self.wrap(self.read_set())
if c == '"': return self.wrap(self.read_literal_binary()) if c == '"': return self.wrap(self.read_literal_binary())
if c == 'x': if c == 'x':
c = self.nextchar() c = self.nextchar()

View File

@ -509,6 +509,8 @@ class ImmutableDict(dict):
v = next(i) v = next(i)
except StopIteration: except StopIteration:
raise DecodeError("Missing dictionary value") raise DecodeError("Missing dictionary value")
if k in result:
raise DecodeError("Duplicate key: " + repr(k))
result_proxy.__setitem__(k, v) result_proxy.__setitem__(k, v)
except StopIteration: except StopIteration:
pass pass