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)
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):
acc = []
while True:
@ -344,7 +352,7 @@ class Parser(TextCodec):
c = self.nextchar()
if c == 'f': return self.wrap(False)
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 == 'x':
c = self.nextchar()

View File

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