bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fix a bug in handling of -i and character type


From: Paolo Bonzini
Subject: [PATCH] fix a bug in handling of -i and character type
Date: Sat, 6 Mar 2010 09:49:27 +0100

Based on the other Debian patch.

* dfa.c (parse_bracket_exp_mb): Convert [[:lower:]] and [[:upper]] to
[[:alpha:]] when folding case.
* tests/case-fold-char-type: New file.  Test for the bug.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
---
 NEWS                      |   10 ++++++----
 src/dfa.c                 |    8 +++++++-
 tests/Makefile.am         |    1 +
 tests/case-fold-char-type |   21 +++++++++++++++++++++
 4 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100644 tests/case-fold-char-type

diff --git a/NEWS b/NEWS
index 6685967..8495635 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ GNU grep NEWS                                    -*- outline -*-
 
   grep -i with a character class would malfunction in multi-byte locales.
   For example, echo Y | LC_ALL=en_US.UTF-8 grep -i '[y]' would print nothing.
+  Character types would malfunction in multi-byte locales similarly; for
+  example, echo Y | LC_ALL=en_US.UTF-8 grep -i '[[:lower:]]' would print
+  nothing.
 
   grep would mistakenly exit with status 1 upon error, rather than 2,
   as it is documented to do.
diff --git a/src/dfa.c b/src/dfa.c
index 1da45fa..e151ecc 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -561,8 +561,14 @@ parse_bracket_exp_mb (void)
                /* build character class.  */
                {
                  wctype_t wt;
+
                  /* Query the character class as wctype_t.  */
-                 wt = wctype (str);
+                 if (case_fold
+                     && (!strcasecmp (str, "upper")
+                         || !strcasecmp (str, "lower")))
+                   wt = wctype ("alpha");
+                 else
+                   wt = wctype (str);
 
                  if (ch_classes_al == 0)
                    MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a2ab198..dffe1f9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,7 @@ TESTS =                                               \
   backref.sh                                   \
   bre.sh                                       \
   case-fold-char-class                         \
+  case-fold-char-type                          \
   empty.sh                                     \
   ere.sh                                       \
   file.sh                                      \
diff --git a/tests/case-fold-char-type b/tests/case-fold-char-type
new file mode 100644
index 0000000..f3a19b4
--- /dev/null
+++ b/tests/case-fold-char-type
@@ -0,0 +1,21 @@
+#!/bin/sh
+# This would fail for grep-2.5.3
+: ${srcdir=.}
+. "$srcdir/init.sh"; path_prepend_ ../src
+
+printf 'Y\n'      > exp1 || framework_failure
+fail=0
+
+for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
+  printf '1\nY\n.\n' | LC_ALL=$LOC grep -i '[[:lower:]]' > out1 || fail=1
+  compare out1 exp1 || fail=1
+done
+
+printf 'y\n'      > exp2 || framework_failure
+
+for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
+  printf '1\ny\n.\n' | LC_ALL=$LOC grep -i '[[:upper:]]' > out2 || fail=1
+  compare out2 exp2 || fail=1
+done
+
+Exit $fail
-- 
1.6.6





reply via email to

[Prev in Thread] Current Thread [Next in Thread]