fix: do not allow GREP_XXX env vars from breaking `rlocation` (#36)
The grep command can be influenced by `GREP_XXX` environment variables.
If set, they can affect the behavior/output of the command, causing
`rlocation` to fail.
diff --git a/shell/runfiles/runfiles.bash b/shell/runfiles/runfiles.bash
index f618b2c..e2dfd20 100644
--- a/shell/runfiles/runfiles.bash
+++ b/shell/runfiles/runfiles.bash
@@ -113,7 +113,9 @@
# Does not exit with a non-zero exit code if no match is found and performs a case-insensitive
# search on Windows.
function __runfiles_maybe_grep() {
- grep $_RLOCATION_GREP_CASE_INSENSITIVE_ARGS "$@" || test $? = 1;
+ # The GREP_XXX variables influence how grep behaves. Specifically, they can
+ # affect the output from the grep command.
+ GREP_COLOR="" GREP_OPTIONS="" grep $_RLOCATION_GREP_CASE_INSENSITIVE_ARGS "$@" || test $? = 1;
}
export -f __runfiles_maybe_grep
diff --git a/tests/runfiles/runfiles_test.bash b/tests/runfiles/runfiles_test.bash
index fb61b86..f738b3d 100755
--- a/tests/runfiles/runfiles_test.bash
+++ b/tests/runfiles/runfiles_test.bash
@@ -522,6 +522,13 @@
[[ -z "${RUNFILES_MANIFEST_FILE:-}" ]] || fail
}
+function test_with_grep_env_vars_set() {
+ # These influence how grep behaves.
+ export GREP_COLOR='1;35;40'
+ export GREP_OPTIONS='--color=always'
+ test_init_manifest_based_runfiles
+}
+
function main() {
local -r manifest_file="${RUNFILES_MANIFEST_FILE:-}"
local -r dir="${RUNFILES_DIR:-}"