def load_string(self):
orig = self.readline()
rep = orig[:-1]
- for q in (b'"', b"'"): # double or single quote
- if rep.startswith(q):
- if len(rep) < 2 or not rep.endswith(q):
- raise ValueError("insecure string pickle")
- rep = rep[len(q):-len(q)]
- break
+ # Strip outermost quotes
- if rep[0] == rep[-1] and rep[0] in b'"\'':
++ if len(rep) >= 2 and rep[0] == rep[-1] and rep[0] in b'"\'':
+ rep = rep[1:-1]
else:
- raise ValueError("insecure string pickle: %r" % orig)
+ raise ValueError("insecure string pickle")
self.append(codecs.escape_decode(rep)[0]
.decode(self.encoding, self.errors))
dispatch[STRING[0]] = load_string