From d35b411a29422769eb861d4c8d424f97a0292a9d Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <noritnk@kcn.ne.jp>
Date: Sun, 5 Oct 2014 20:57:32 -0700
Subject: [PATCH] dfa: test for just-fixed bug

* tests/mb-dot-newline: New file.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
Also see
http://debbugs.gnu.org/cgi/bugreport.cgi?msg=17;bug=18580
---
 NEWS                 | 17 +++++++++++++++++
 tests/Makefile.am    |  1 +
 tests/mb-dot-newline | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100755 tests/mb-dot-newline

diff --git a/NEWS b/NEWS
index a146e9e..07a5d54 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,23 @@ GNU grep NEWS                                    -*- outline -*-

 ** Bug fixes

+  grep would fail to count newlines internally when operating in non-UTF8
+  multibyte locales, leading it to print potentially many lines that did
+  not match.  E.g., the command, "seq 10 | env LC_ALL=zh_CN src/grep -n .."
+  would print this:
+  1:1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+  10
+  implying that the match, "10" was on line 1.
+  [bug introduced in grep-2.19]
+
   grep -E rejected unmatched ')', instead of treating it like '\)'.
   [bug present since "the beginning"]

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4b9a931..c298835 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ TESTS =						\
   long-line-vs-2GiB-read			\
   max-count-overread				\
   max-count-vs-context				\
+  mb-dot-newline				\
   mb-non-UTF8-overrun				\
   mb-non-UTF8-performance			\
   multibyte-white-space				\
diff --git a/tests/mb-dot-newline b/tests/mb-dot-newline
new file mode 100755
index 0000000..5fab82b
--- /dev/null
+++ b/tests/mb-dot-newline
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Trigger a bug in the DFA matcher.
+# This would fail for grep-2.20.
+
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+printf 'a\naa\n' > in || framework_failure_
+printf 'aa\n' > exp || framework_failure_
+
+fail=0
+
+for LOC in en_US.UTF-8 en_US zh_CN $LOCALE_FR_UTF8 C; do
+  out1=out1-$LOC
+  LC_ALL=$LOC grep '..' in > out || fail=1
+  compare exp out || fail=1
+done
+
+Exit $fail
-- 
2.0.0.421.g786a89d

