Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/dispatch.py @ 37142:aa55c5354b8f
alias: reject non-ascii characters in user help/doc strings
Since command doc/help texts are passed to i18n.gettext(), they must be
ASCII. Otherwise, UnicodeError would be raised.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 28 Mar 2018 22:04:45 +0900 |
parents | 6890b7e991a4 |
children | 1d56c539794e |
comparison
equal
deleted
inserted
replaced
37141:4d63f3bc1e1a | 37142:aa55c5354b8f |
---|---|
532 except error.AmbiguousCommand: | 532 except error.AmbiguousCommand: |
533 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'") | 533 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'") |
534 % (self.name, cmd)) | 534 % (self.name, cmd)) |
535 | 535 |
536 def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None): | 536 def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None): |
537 self.help = ui.config('alias', '%s:help' % name, defaulthelp or '') | 537 # confine strings to be passed to i18n.gettext() |
538 cfg = {} | |
539 for k in ('doc', 'help'): | |
540 v = ui.config('alias', '%s:%s' % (name, k), None) | |
541 if v is None: | |
542 continue | |
543 if not encoding.isasciistr(v): | |
544 self.badalias = (_("non-ASCII character in alias definition " | |
545 "'%s:%s'") % (name, k)) | |
546 return | |
547 cfg[k] = v | |
548 | |
549 self.help = cfg.get('help', defaulthelp or '') | |
538 if self.help and self.help.startswith("hg " + cmd): | 550 if self.help and self.help.startswith("hg " + cmd): |
539 # drop prefix in old-style help lines so hg shows the alias | 551 # drop prefix in old-style help lines so hg shows the alias |
540 self.help = self.help[4 + len(cmd):] | 552 self.help = self.help[4 + len(cmd):] |
541 | 553 |
542 self.__doc__ = ui.config('alias', '%s:doc' % name, fn.__doc__) | 554 self.__doc__ = cfg.get('doc', fn.__doc__) |
543 | 555 |
544 @property | 556 @property |
545 def args(self): | 557 def args(self): |
546 args = pycompat.maplist(util.expandpath, self.givenargs) | 558 args = pycompat.maplist(util.expandpath, self.givenargs) |
547 return aliasargs(self.fn, args) | 559 return aliasargs(self.fn, args) |