Mercurial > hg
comparison tests/test-help.t @ 29155:aaabed77791a stable 3.8.2
help: search section of help topic by translated section name correctly
Before this patch, "hg help topic.section" might show unexpected
section of help topic in some encoding.
It applies str.lower() instead of encoding.lower(str) on translated
message to search section case-insensitively, 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 search section of help topic by translated section name correctly,
this patch replaces str.lower() by encoding.lower(str) for both query
string (in commands.help()) and translated help text (in
minirst.getsections()).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 13 May 2016 07:19:59 +0900 |
parents | eb017d52899d |
children | 8c8442523eef |
comparison
equal
deleted
inserted
replaced
29154:9d38a2061fd8 | 29155:aaabed77791a |
---|---|
1522 | 1522 |
1523 $ hg help template.files | 1523 $ hg help template.files |
1524 files List of strings. All files modified, added, or removed by | 1524 files List of strings. All files modified, added, or removed by |
1525 this changeset. | 1525 this changeset. |
1526 | 1526 |
1527 Test section lookup by translated message | |
1528 | |
1529 str.lower() instead of encoding.lower(str) on translated message might | |
1530 make message meaningless, because some encoding uses 0x41(A) - 0x5a(Z) | |
1531 as the second or later byte of multi-byte character. | |
1532 | |
1533 For example, "\x8bL\x98^" (translation of "record" in ja_JP.cp932) | |
1534 contains 0x4c (L). str.lower() replaces 0x4c(L) by 0x6c(l) and this | |
1535 replacement makes message meaningless. | |
1536 | |
1537 This tests that section lookup by translated string isn't broken by | |
1538 such str.lower(). | |
1539 | |
1540 $ python <<EOF | |
1541 > def escape(s): | |
1542 > return ''.join('\u%x' % ord(uc) for uc in s.decode('cp932')) | |
1543 > # translation of "record" in ja_JP.cp932 | |
1544 > upper = "\x8bL\x98^" | |
1545 > # str.lower()-ed section name should be treated as different one | |
1546 > lower = "\x8bl\x98^" | |
1547 > with open('ambiguous.py', 'w') as fp: | |
1548 > fp.write("""# ambiguous section names in ja_JP.cp932 | |
1549 > u'''summary of extension | |
1550 > | |
1551 > %s | |
1552 > ---- | |
1553 > | |
1554 > Upper name should show only this message | |
1555 > | |
1556 > %s | |
1557 > ---- | |
1558 > | |
1559 > Lower name should show only this message | |
1560 > | |
1561 > subsequent section | |
1562 > ------------------ | |
1563 > | |
1564 > This should be hidden at "hg help ambiguous" with section name. | |
1565 > ''' | |
1566 > """ % (escape(upper), escape(lower))) | |
1567 > EOF | |
1568 | |
1569 $ cat >> $HGRCPATH <<EOF | |
1570 > [extensions] | |
1571 > ambiguous = ./ambiguous.py | |
1572 > EOF | |
1573 | |
1574 $ python <<EOF | sh | |
1575 > upper = "\x8bL\x98^" | |
1576 > print "hg --encoding cp932 help -e ambiguous.%s" % upper | |
1577 > EOF | |
1578 \x8bL\x98^ (esc) | |
1579 ---- | |
1580 | |
1581 Upper name should show only this message | |
1582 | |
1583 | |
1584 $ python <<EOF | sh | |
1585 > lower = "\x8bl\x98^" | |
1586 > print "hg --encoding cp932 help -e ambiguous.%s" % lower | |
1587 > EOF | |
1588 \x8bl\x98^ (esc) | |
1589 ---- | |
1590 | |
1591 Lower name should show only this message | |
1592 | |
1593 | |
1594 $ cat >> $HGRCPATH <<EOF | |
1595 > [extensions] | |
1596 > ambiguous = ! | |
1597 > EOF | |
1598 | |
1527 Test dynamic list of merge tools only shows up once | 1599 Test dynamic list of merge tools only shows up once |
1528 $ hg help merge-tools | 1600 $ hg help merge-tools |
1529 Merge Tools | 1601 Merge Tools |
1530 """"""""""" | 1602 """"""""""" |
1531 | 1603 |