From 63611bb308130d4c566382c0f36cec0c88915a7f Mon Sep 17 00:00:00 2001 From: FUJIWARA Katsunori Date: Fri, 13 May 2016 07:19:59 +0900 Subject: [PATCH] patch: show lower-ed translated message correctly Before this patch, patch.filterpatch() shows meaningless translation of help message for chunk selection in some encoding. It applies str.lower() instead of encoding.lower(str) on translated message, but some encoding uses 0x41(A) - 0x5a(Z) as the second or later byte of multi-byte character (for example, ja_JP.cp932), and str.lower() causes unexpected result. To show lower-ed translated message correctly, this patch replaces str.lower() by encoding.lower(str). --- mercurial/patch.py | 2 +- tests/test-commit-interactive.t | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mercurial/patch.py b/mercurial/patch.py index b576cce2af..9e5884032a 100644 --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1010,7 +1010,7 @@ def filterpatch(ui, headers, operation=None): ui.write("\n") if r == 8: # ? for c, t in ui.extractchoices(resps)[1]: - ui.write('%s - %s\n' % (c, t.lower())) + ui.write('%s - %s\n' % (c, encoding.lower(t))) continue elif r == 0: # yes ret = True diff --git a/tests/test-commit-interactive.t b/tests/test-commit-interactive.t index 3658b4c310..db44d85200 100644 --- a/tests/test-commit-interactive.t +++ b/tests/test-commit-interactive.t @@ -878,6 +878,32 @@ Help, quit abort: user quit [255] +#if gettext + +Test translated help message + +str.lower() instead of encoding.lower(str) on translated message might +make message meaningless, because some encoding uses 0x41(A) - 0x5a(Z) +as the second or later byte of multi-byte character. + +For example, "\x8bL\x98^" (translation of "record" in ja_JP.cp932) +contains 0x4c (L). str.lower() replaces 0x4c(L) by 0x6c(l) and this +replacement makes message meaningless. + +This tests that translated help message is lower()-ed correctly. + + $ LANGUAGE=ja + $ export LANGUAGE + + $ hg commit -i --encoding cp932 2>&1 < ? + > q + > EOF + y - \x82\xb1\x82\xcc\x95\xcf\x8dX\x82\xf0\x8bL\x98^(yes) (esc) + + $ LANGUAGE= +#endif + Skip $ hg commit -i <