summaryrefslogtreecommitdiff
path: root/tests/prefix-of-multibyte
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-05-05 20:19:19 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-05-05 20:19:59 -0700
commiteb3292b3b205e50d0373f26ff0950ec82f49c14a (patch)
treebfcb18201f277f03886e83efedfc070693652d45 /tests/prefix-of-multibyte
parent17683df11fbea7aa01c9d60f1b45874c9ea5e26a (diff)
downloadgrep-eb3292b3b205e50d0373f26ff0950ec82f49c14a.tar.gz
grep: fix encoding-error incompatibilities among regex, DFA, KWset
This follows up to http://bugs.gnu.org/17376 and fixes a different set of incompatibilities, namely between the regex matcher and the other matchers, when the pattern contains encoding errors. The GNU regex matcher is not consistent in this area: sometimes an encoding error matches only itself, and sometimes it matches part of a multibyte character. There is no documentation for grep's behavior in this area and users don't seem to care, and it's simpler to defer to the regex matcher for problematic cases like these. * NEWS: Document this. * src/dfa.c (ctok): Remove. All uses removed. (parse_bracket_exp, atom): Use BACKREF if a pattern contains an encoding error, so that the matcher will revert to regex. * src/dfasearch.c, src/grep.c, src/pcresearch.c, src/searchutils.c: Don't include dfa.h, since search.h now does that for us. * src/dfasearch.c (EGexecute): * src/kwsearch.c (Fexecute): In a UTF-8 locale, there's no need to worry about matching part of a multibyte character. * src/grep.c (contains_encoding_error): New static function. (main): Use it, so that grep -F is consistent with plain fgrep when the pattern contains an encoding error. * src/search.h: Include dfa.h, so that kwsearch.c can call using_utf8. * src/searchutils.c (is_mb_middle): Remove UTF-8-specific code. Callers now ensure that we are in a non-UTF-8 locale. The code was clearly wrong, anyway. * tests/fgrep-infloop, tests/invalid-multibyte-infloop: * tests/prefix-of-multibyte: Do not require that grep have a particular behavor for this test. It's OK to match (exit status 0), not match (exit status 1), or report an error (exit status 2), since the pattern contains an encoding error and grep's behavior is not specified for such patterns. Test only that KWset, DFA, and regex agree. * tests/prefix-of-multibyte: Add tests for ABCABC and __..._ABCABC___.
Diffstat (limited to 'tests/prefix-of-multibyte')
-rwxr-xr-xtests/prefix-of-multibyte36
1 files changed, 25 insertions, 11 deletions
diff --git a/tests/prefix-of-multibyte b/tests/prefix-of-multibyte
index 2ab9a99a..2228a22b 100755
--- a/tests/prefix-of-multibyte
+++ b/tests/prefix-of-multibyte
@@ -9,21 +9,35 @@ encode() { echo "$1" | tr ABC '\357\274\241'; }
encode ABC >exp1
encode aABC >exp2
+encode ABCABC >exp3
+encode _____________________ABCABC___ >exp4
fail=0
for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
- for type in dfa fgrep regex; do
- case $type in
- dfa) opt= prefix= ;;
- fgrep) opt=-F prefix= ;;
- regex) opt= prefix='\(\)\1' ;;
- esac
- out=out-$type-$LOC
- LC_ALL=$LOC grep $opt "$prefix$(encode A)" exp1 >$out || fail=1
- compare exp1 $out || fail=1
- LC_ALL=$LOC grep $opt "$prefix$(encode aA)" exp2 >$out || fail=1
- compare exp2 $out || fail=1
+ for pat in A aA BCA; do
+ for file in exp1 exp2 exp3 exp4; do
+ for type in regex dfa fgrep; do
+ case $type in
+ dfa) opt= prefix= ;;
+ fgrep) opt=-F prefix= ;;
+ regex) opt= prefix='\(\)\1' ;;
+ esac
+ pattern=$prefix$(encode $pat)
+ out=out-$type-$LOC
+ LC_ALL=$LOC grep $opt "$pattern" $file >$out
+ status=$?
+ echo $status >$out.status
+ if test $status -eq 0; then
+ compare $file $out
+ elif test $status -eq 1; then
+ compare_dev_null_ /dev/null $out
+ else
+ test $status -eq 2
+ fi || fail=1
+ compare out-regex-$LOC.status $out.status || fail=1
+ done
+ done
done
done