about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-11-17 23:21:14 +0100
committerbptato <nincsnevem662@gmail.com>2023-11-17 23:23:08 +0100
commitd1b6a1ca3ab18fa90564dae6a303011d6c07047d (patch)
treecf069941f8af5d0dc75ea80108a1ed233f649982
parent6b2226febd53a75dc4d45963dd8f7ab8249d78dc (diff)
downloadchawan-d1b6a1ca3ab18fa90564dae6a303011d6c07047d.tar.gz
cha-finger: bugfixes
* Accept port 79, not 73
* Accept ipv6 addresses
* We no longer have to URL decode the input
-rwxr-xr-xbonus/finger/cha-finger13
1 files changed, 3 insertions, 10 deletions
diff --git a/bonus/finger/cha-finger b/bonus/finger/cha-finger
index 7adf231b..a0f68ef5 100755
--- a/bonus/finger/cha-finger
+++ b/bonus/finger/cha-finger
@@ -7,22 +7,15 @@
 #
 # finger: file:/cgi-bin/cha-finger?%s
 
-decode() {
-	# URL-decode the string passed as the first parameter
-	printf '%s\n' "$1" | \
-		sed 's/+/ /g;s/%/\\x/g' | \
-		xargs -0 printf "%b"
-}
-
 printf 'Content-Type: text/plain\r\n\r\n'
 if test -z "$QUERY_STRING"
 then	echo "URL expected"
 	exit 1
 fi
+URL="$(printf '%s\n' "$QUERY_STRING" | \
+	sed 's/^finger:\/\///;s/^\([^[]\/:]\|\[[^]:]*\]\):79/\1/')"
 
-URL="$(decode "$QUERY_STRING" | sed 's/^finger:\/\///;s/^\([^/]*\):73/\1/')"
-
-if printf '%s\n' "$URL" | grep -q '^[^/]*:[0-9]'
+if printf '%s\n' "$URL" | grep -q '^\([^[]/]*\)\|\(\[[^]]*\]\):[0-9]'
 then	echo "Invalid port"
 	exit 1
 fi