+2006-11-26 Paul Eggert <eggert@cs.ucla.edu>
+
+ * zgrep.in: If the file name contains newline, &, \, or |, escape
+ the character so that 'sed' doesn't mishandle it as a replacement.
+ Problem reported by Bdale Garbee.
+
2006-11-25 Paul Eggert <eggert@cs.ucla.edu>
* gzip.1 (OPTIONS): ouput -> output. Problem reported by Matt
elif test $with_filename -eq 0 && { test $# -eq 1 || test $no_filename -eq 1; }; then
$grep $opt "$pat"
else
+ escaped=
+ while :; do
+ case $i in
+ *'
+'*)
+ char='
+' repl='\\n';;
+ *'&'*) char='&' repl='\&';;
+ *'\'*) char='\\' repl='\\';;
+ *'|'*) char='|' repl='\|';;
+ *) break;;
+ esac
+ up_to_first_char="\\([^$char]*\\)"
+ after_first_char="[^$char]*$char\\(.*\\)"
+ escaped=$escaped`expr "X$i" : "X$up_to_first_char"`$repl
+ i=`expr "X$i" : "$after_first_char"`
+ done
if test $with_filename -eq 1; then
- sed_script="s|^[^:]*:|${i}:|"
+ sed_script="s|[^:]*|$escaped$i|"
else
- sed_script="s|^|${i}:|"
+ sed_script="s|^|$escaped$i:|"
fi
# Fail if either grep or sed fails.