Skip to content

Commit f7ceb28

Browse files
committed
Implement --prefix parameter checking.
Also add -p to the getopt list of short options.
1 parent 4c14da4 commit f7ceb28

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ GETOPT=$(getopt \
194194
--longoptions=default-exclude,dry-run,skip-scrub,recursive \
195195
--longoptions=keep:,label:,prefix:,sep: \
196196
--longoptions=debug,help,quiet,syslog,verbose \
197-
--options=dnshl:k:rs:qgv \
197+
--options=dnshl:k:p:rs:qgv \
198198
-- "$@" ) \
199199
|| exit 1
200200

@@ -239,8 +239,19 @@ do
239239
shift 2
240240
;;
241241
(-p|--prefix)
242-
# @TODO: Parameter validation. See --sep below for the regex.
243242
opt_prefix="$2"
243+
while test "${#opt_prefix}" -gt '0'
244+
do
245+
case $opt_prefix in
246+
([![:alnum:]_-.:\ ]*)
247+
print_log error "The $1 parameter must be alphanumeric."
248+
exit 44
249+
;;
250+
esac
251+
opt_prefix="${opt_prefix#?}"
252+
done
253+
opt_prefix="$2"
254+
shift 2
244255
;;
245256
(-q|--quiet)
246257
opt_debug=''

0 commit comments

Comments
 (0)