From ad9cf023d2c853f833d6c9097b86360da55002a8 Mon Sep 17 00:00:00 2001 From: Jianhui Yuan Xu <107997665+NeumoNeumo@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:39:02 +0800 Subject: [PATCH] Fix: encode URL in the bash client curl sometimes cannot work when encountering commands with special characters like `curl -s 'https://domain/filename with spaces.txt' > filename with spaces.txt` Before outputting the command, we need to encode the URL first. --- client/plik.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/client/plik.sh b/client/plik.sh index 77b57e22..76d6ccb0 100755 --- a/client/plik.sh +++ b/client/plik.sh @@ -33,6 +33,27 @@ function setTtl() { esac return } +# The following snippet is modified from +# https://stackoverflow.com/a/10660730/17792535 +# Snippet Start +function rawURLEncode() { + local string="${1}" + local strlen=${#string} + local encoded="" + local pos c o + + for (( pos=0 ; pos