Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/dispatch.py Mon Mar 26 22:18:36 2018 -0400 +++ b/mercurial/dispatch.py Wed Mar 28 22:04:45 2018 +0900 @@ -534,12 +534,24 @@ % (self.name, cmd)) def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None): - self.help = ui.config('alias', '%s:help' % name, defaulthelp or '') + # confine strings to be passed to i18n.gettext() + cfg = {} + for k in ('doc', 'help'): + v = ui.config('alias', '%s:%s' % (name, k), None) + if v is None: + continue + if not encoding.isasciistr(v): + self.badalias = (_("non-ASCII character in alias definition " + "'%s:%s'") % (name, k)) + return + cfg[k] = v + + self.help = cfg.get('help', defaulthelp or '') if self.help and self.help.startswith("hg " + cmd): # drop prefix in old-style help lines so hg shows the alias self.help = self.help[4 + len(cmd):] - self.__doc__ = ui.config('alias', '%s:doc' % name, fn.__doc__) + self.__doc__ = cfg.get('doc', fn.__doc__) @property def args(self):