comparison mercurial/obsolete.py @ 38708:ff1182d166a2

obsolete: explode if metadata contains invalid UTF-8 sequence (API) The current metadata API can be a source of bugs since it forces callers to process encoding conversion by themselves. So let's make it reject bad data as a last ditch. I assume there's no metadata field which is supposed to store arbitrary BLOB like transplant_source.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 15 Jul 2018 18:32:17 +0900
parents 6b5ca1d0aa1e
children e7aa113b14f7
comparison
equal deleted inserted replaced
38707:6b5ca1d0aa1e 38708:ff1182d166a2
78 error, 78 error,
79 node, 79 node,
80 obsutil, 80 obsutil,
81 phases, 81 phases,
82 policy, 82 policy,
83 pycompat,
83 util, 84 util,
84 ) 85 )
85 from .utils import dateutil 86 from .utils import dateutil
86 87
87 parsers = policy.importmod(r'parsers') 88 parsers = policy.importmod(r'parsers')
598 raise ValueError(succ) 599 raise ValueError(succ)
599 if prec in succs: 600 if prec in succs:
600 raise ValueError(_('in-marker cycle with %s') % node.hex(prec)) 601 raise ValueError(_('in-marker cycle with %s') % node.hex(prec))
601 602
602 metadata = tuple(sorted(metadata.iteritems())) 603 metadata = tuple(sorted(metadata.iteritems()))
604 for k, v in metadata:
605 try:
606 # might be better to reject non-ASCII keys
607 k.decode('utf-8')
608 v.decode('utf-8')
609 except UnicodeDecodeError:
610 raise error.ProgrammingError(
611 'obsstore metadata must be valid UTF-8 sequence '
612 '(key = %r, value = %r)'
613 % (pycompat.bytestr(k), pycompat.bytestr(v)))
603 614
604 marker = (bytes(prec), tuple(succs), int(flag), metadata, date, parents) 615 marker = (bytes(prec), tuple(succs), int(flag), metadata, date, parents)
605 return bool(self.add(transaction, [marker])) 616 return bool(self.add(transaction, [marker]))
606 617
607 def add(self, transaction, markers): 618 def add(self, transaction, markers):