summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--src/grep.c7
2 files changed, 8 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 33658fc7..0a18a9e7 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@ GNU grep NEWS -*- outline -*-
The confusing GREP_COLOR environment variable is now obsolescent.
Instead of GREP_COLOR='xxx', use GREP_COLORS='mt=xxx'. grep now
warns if GREP_COLOR is used and is not overridden by GREP_COLORS.
+ Also, grep now treates GREP_COLOR like GREP_COLORS by silently
+ ignoring it if it attempts to inject ANSI terminal escapes.
Regular expressions with stray backslashes now cause warnings, as
their unspecified behavior can lead to unexpected results.
diff --git a/src/grep.c b/src/grep.c
index edefac6c..59d34310 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2911,7 +2911,12 @@ main (int argc, char **argv)
/* Legacy. */
char *userval = getenv ("GREP_COLOR");
if (userval != NULL && *userval != '\0')
- selected_match_color = context_match_color = userval;
+ for (char *q = userval; *q == ';' || c_isdigit (*q); q++)
+ if (!q[1])
+ {
+ selected_match_color = context_match_color = userval;
+ break;
+ }
/* New GREP_COLORS has priority. */
parse_grep_colors ();