Subject: bug#54291: closed (Re: bug#54291: zdiff can not handle options properly)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 07 Mar 2022 17:45:02 +0000

Your bug report

#54291: zdiff can not handle options properly

which was filed against the gzip package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
54291: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=54291
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#54291: zdiff can not handle options properly
From: Paul Eggert <[email-masked]>
To: CAKxHvy1w=ubGoLSKcGe8mwU36MYjHvXLW_1j3=[email-masked]
Cc: [email-masked], [email-masked], [email-masked]
Date: Mon, 7 Mar 2022 09:44:06 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

On 3/7/22 01:32, Lv Ying via GNU gzip discussion and bug reports. wrote:

> 2. rewrite options parse function make it work just like diff.

Thanks for reporting the problem. I installed the attached to implement 
the above suggestion, and this should appear in the next gzip release.
From 40d96d894003f4a6ce07bafbb7ff61450ec9d7bc Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Mon, 7 Mar 2022 09:38:08 -0800
Subject: [PATCH] zdiff: fix arg handling bug

Problem reported by Lv Ying (Bug#54291).
* zdiff.in (escape): Handle args like '-C 5'.
---
 NEWS     |  4 ++++
 zdiff.in | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 19049f8..05b4166 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ GNU gzip NEWS                                    -*- outline -*-
   much more time, nowadays the correctness pros seem to outweigh the
   performance cons.
 
+** Bug fixes
+
+  'zdiff -C 5' no longer misbehaves by treating '5' as a file name.
+
 
 * Noteworthy changes in release 1.11 (2021-09-03) [stable]
 
diff --git a/zdiff.in b/zdiff.in
index 7c92251..d982d9f 100644
--- a/zdiff.in
+++ b/zdiff.in
@@ -49,14 +49,23 @@ escape='
 '
 
 while :; do
+  argdone=:
   case $1 in
   --h*) printf '%s\n' "$usage"   || exit 2; exit;;
   --v*) printf '%s\n' "$version" || exit 2; exit;;
   --) shift; break;;
-  -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
+  -*\'*) argdone=false arg=$1;;
+  -[CDFISUWXx])
+    cmp="$cmp $1"
+    case ${2?} in
+    -*\'*) argdone=false arg=$2;;
+    *) cmp="$cmp '$2'";;
+    esac
+    shift;;
   -?*) cmp="$cmp '$1'";;
   *) break;;
   esac
+  $argdone || cmp="$cmp '"`printf '%sX\n' "$arg" | sed "$escape"`
   shift
 done
 cmp="$cmp --"
-- 
2.32.0

Subject: zdiff can not handle options properly
From: Lv Ying <[email-masked]>
To: <[email-masked]>, <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Mon, 7 Mar 2022 17:32:45 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

As Bram Mertens mentioned in bug#35209:
"diff -y -W 200 /tmp/b1 /tmp/b2". But when passed to zdiff the space 
between "-W" and 200 causes the COLUMNS argument to be interpreted as a 
file:
zdiff -y -W 200 /tmp/b1 /tmp/b2
/bin/zdiff: 72: /bin/zdiff: cannot open 200: No such file

I reproduce this problem in gzip 1.11:
zdiff -y -W200 a.gz b.gz
aaaa                            |    bbbb
zdiff -y -W 200 a.gz b.gz
zdiff: line 66: 200: No such file or directory

Also, file before options is not supported:
zdiff a.gz b.gz -y -W200
zdiff: line 66: -y: No such file or directory
diff a b -y -W 200
aaaa                            |    bbbb

This is because zdiff.in implement option parse is simple. zdiff.in 
first parse all the options by while loop.
The use cmp="$cmp --" sperate options and file arguments. It is 
understandable that zdiff does not want to repeat the parameter parsing 
work of diff. So, use the simple option parse here.

However, the usage string said "Do comparisons like 'diff' does." Such 
usage will misldead the user just as bug#35209 mentioned.

There are two suggestions we may discuss:
1. update usage string, add detailed restricted instructions: e.g NO 
space between option and option argument, all the options should come 
before the filename parameter.
2. rewrite options parse function make it work just like diff.

-- 
Thanks!
Lv Ying