[vorbis-tools] 02/03: Fix vorbistagedit: Correctly process input files containing spaces
Martin Steghöfer
martin.steghoefer-guest at moszumanska.debian.org
Fri Dec 5 16:37:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
martin.steghoefer-guest pushed a commit to branch jessie-fixes
in repository vorbis-tools.
commit 326f6810ec6d7c55e06176b2d764f0b4b1d28148
Author: Martin Steghöfer <martin at steghoefer.eu>
Date: Sat Nov 29 13:15:54 2014 +0100
Fix vorbistagedit: Correctly process input files containing spaces
With filenames containing spaces were splitted at the spaces and the
components were treated as individual parameters/filenames, even if
the filenames were quoted/escaped correctly on the command line.
This was due to the interpretation of the output of "getopt" without
taking into account its quoting. "GNU getopt" quotes its output,
so it can be correctly split into parameters. However, just using
that output in a for loop doesn't take into account that quoting,
but splits the output string at every space regardless its quoting.
To avoid this, the output of "getopt" is now parsed using
"eval set --", which overwrites the original command-line parameters
with the ones provided by "getopt", taking into account quoting.
Iterating over those parameters using a "while" loop with the
"shift" command (to advance) provides an additional positive effect:
The possibility to process all options in the first loop and all
filenames in a second loop. Before, the filename loop processed
all options a second time. Therefore you could only have options
that exited immediately.
Closes: #763338
---
debian/extra/vorbistagedit | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/debian/extra/vorbistagedit b/debian/extra/vorbistagedit
index f4109ff..50e9073 100644
--- a/debian/extra/vorbistagedit
+++ b/debian/extra/vorbistagedit
@@ -32,7 +32,13 @@ if [ $# -eq 0 ]; then
exit 1
fi
-for opt in $(getopt -n $ME -l version,help -o Vh? -- "$@"); do
+# process and reorder arguments using "getopt"
+eval set -- $(getopt -s sh -n $ME -l version,help -o Vh? -- "$@")
+
+# process the options (not the filenames yet) and remove them from the argument array
+while [ $# -gt 0 ]
+do
+ opt="$1"
case $opt in
--version|-V)
versioninfo
@@ -40,13 +46,23 @@ for opt in $(getopt -n $ME -l version,help -o Vh? -- "$@"); do
--help|-h|-\?)
usage
exit 0;;
- --) :;;
- -*)
+ --)
+ # found "--", which separates options and filenames in "getopt" output;
+ # so we are done parsing the options
+
+ # remove the "--"
+ shift
+
+ # now there are only filenames in the argument array => stop processing
+ break;;
+ *)
echo "E: $ME: invalid argument: $opt" >&2
usage
exit 1;;
- *) :;;
esac
+
+ # remove the processed option from the argument array
+ shift
done
if ! command -v vorbiscomment >/dev/null; then
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-xiph/vorbis-tools.git
More information about the pkg-xiph-commits
mailing list