]> Savannah Git Hosting - gnulib.git/commitdiff
regex: match [...---...] like V7 grep
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Apr 2022 01:56:12 +0000 (18:56 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Apr 2022 02:05:39 +0000 (19:05 -0700)
Problem reported by Arnold Robbins in:
https://bugs.gnu.org/20657
https://lists.gnu.org/r/bug-gnulib/2022-04/msg00053.html
* lib/regcomp.c (peek_token_bracket): Let [...---...] match '-'.
This is an extension to POSIX, and matches V7 Unix grep.

ChangeLog
lib/regcomp.c

index cd16bbe0cde577d1f407899d498c3e49dc123253..ddd4826bcf57f6738dbd0992584543e88d5bf5a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-04-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+       regex: match [...---...] like V7 grep
+       Problem reported by Arnold Robbins in:
+       https://bugs.gnu.org/20657
+       https://lists.gnu.org/r/bug-gnulib/2022-04/msg00053.html
+       * lib/regcomp.c (peek_token_bracket): Let [...---...] match '-'.
+       This is an extension to POSIX, and matches V7 Unix grep.
+
 2022-04-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        backupfile: fix bug when renaming simple backups
index b607c85320f6d0fbc3804b1283dd508b62ad54a4..122c3de58c3eb16eda49c6dfe89839925f74d8a8 100644 (file)
@@ -2038,15 +2038,25 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
     }
   switch (c)
     {
-    case '-':
-      token->type = OP_CHARSET_RANGE;
-      break;
     case ']':
       token->type = OP_CLOSE_BRACKET;
       break;
     case '^':
       token->type = OP_NON_MATCH_LIST;
       break;
+    case '-':
+      /* In V7 Unix grep and Unix awk and mawk, [...---...]
+         (3 adjacent minus signs) stands for a single minus sign.
+         Support that without breaking anything else.  */
+      if (! (re_string_cur_idx (input) + 2 < re_string_length (input)
+             && re_string_peek_byte (input, 1) == '-'
+             && re_string_peek_byte (input, 2) == '-'))
+        {
+          token->type = OP_CHARSET_RANGE;
+          break;
+        }
+      re_string_skip_bytes (input, 2);
+      FALLTHROUGH;
     default:
       token->type = CHARACTER;
     }