Skip to content
Snippets Groups Projects
Commit 8c5e880c authored by Katsunori FUJIWARA's avatar Katsunori FUJIWARA
Browse files

tests: escape bytes setting MSB in input of grep for portability

GNU grep (2.21-2 or later) assumes that input is encoded in LC_CTYPE,
and input is binary if it contains byte sequence not valid for that
encoding.

For example, if locale is configured as C, a byte setting most
significant bit (MSB) makes such GNU grep show "Binary file <FILENAME>
matches" message instead of matched lines unintentionally.

This behavior is recognized as a bug, and fixed in GNU grep 2.25-1 or
later. But some distributions are shipped with such buggy version
(e.g. Ubuntu xenial, which is used by launchpad buildbot).

    http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19230
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800670
    http://packages.ubuntu.com/xenial/grep

This causes failure of test-commit-interactive.t, which applies grep
on CP932 byte sequence since 1111e84de635.

But, explicit setting LC_CTYPE for CP932 might cause another problem,
because it can't be assumed that all environment running Mercurial
tests allows arbitrary locale setting.

To resolve this issue, this patch escapes bytes setting MSB in input
of grep.

For this purpose:

  - str.encode('string-escape') isn't useful, because it escapes also
    control code (less than 0x20), and makes EOL handling complicated

  - "f --hexdump" isn't useful, because it isn't line-oriented

  - "sed -n" seems reasonable, but "sed" itself sometimes causes
    portability issue, too (e.g. 900767dfa80d or afb86ee925bf)

This patch is posted with "stable" flag, because 1111e84de635 is on
stable branch.
parent 854556c5
No related branches found
No related tags found
No related merge requests found
......@@ -895,7 +895,20 @@
$ LANGUAGE=ja
$ export LANGUAGE
$ hg commit -i --encoding cp932 2>&1 <<EOF | grep '^y - '
$ cat > $TESTTMP/escape.py <<EOF
> from __future__ import absolute_import
> import sys
> def escape(c):
> o = ord(c)
> if o < 0x80:
> return c
> else:
> return r'\x%02x' % o # escape char setting MSB
> for l in sys.stdin:
> sys.stdout.write(''.join(escape(c) for c in l))
> EOF
$ hg commit -i --encoding cp932 2>&1 <<EOF | python $TESTTMP/escape.py | grep '^y - '
> ?
> q
> EOF
......@@ -899,7 +912,7 @@
> ?
> q
> EOF
y - \x82\xb1\x82\xcc\x95\xcf\x8dX\x82\xf0\x8bL\x98^(yes) (esc)
y - \x82\xb1\x82\xcc\x95\xcf\x8dX\x82\xf0\x8bL\x98^(yes)
$ LANGUAGE=
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment