From 44e88ed586bdefb50d7165772367e0ee24acd5b2 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 19 Jul 2024 08:21:03 -0700 Subject: [PATCH] add URL-encoding to `grab` now files with spaces work properly, yippee --- sh/grab | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sh/grab b/sh/grab index 808f23e..b926a1e 100755 --- a/sh/grab +++ b/sh/grab @@ -20,6 +20,15 @@ x=${?#0} printf "failed to %s\n" "$task" >&2 exit ${x:-1} } +esc(){ +while [ -n "$1" ]; do +case "$1" in +([\!\"$\&-\>@-~]*) printf '%.1s' "$1";; +(*) printf '%%%02X' "'$1";; +esac +set -- "${1#?}" +done +} 2>&- get(){ if [ -f /usr/bin/curl ] then curl -sSfLgm5 -o "$@" @@ -61,6 +70,7 @@ esac || die touch -- "$fn" || die will ensure supported protocols # busybox restricts this +fx="$(esc "$fn")" case "$f" in (http://*);; (https://*);; @@ -70,9 +80,9 @@ case "$f" in printf 'unsupported protocol: %s\n' "${f%%:*}" >&2 die;; (*) -f="https://$remote/$fn";; +f="https://$remote/$fx";; esac -g="https://$remote/$fn.minisig" +g="https://$remote/$fx.minisig" will download "$fn" from "$f" get "$fn" -- "$f" || die