From 9f3cc02d0b5a4da0a9bc2baba4c4beea2603edc1 Mon Sep 17 00:00:00 2001 From: Fabio Date: Fri, 16 Feb 2018 10:08:12 +0100 Subject: [PATCH] Decode the URI before handling it. --- bashttpd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bashttpd b/bashttpd index 9ed8d21..797f4cf 100755 --- a/bashttpd +++ b/bashttpd @@ -249,6 +249,11 @@ unconditionally() { "$@" "$REQUEST_URI" } +# Taken from https://stackoverflow.com/a/6265305/566849 +uri_decode() { + echo -e "$(sed 's/+/ /g;s/%\(..\)/\\x\1/g;')" +} + # Request-Line HTTP RFC 2616 $5.1 read -r line || fail_with 400 @@ -266,6 +271,8 @@ read -r REQUEST_METHOD REQUEST_URI REQUEST_HTTP_VERSION <<<"$line" # Only GET is supported at this time [ "$REQUEST_METHOD" = "GET" ] || fail_with 405 +REQUEST_URI=$(uri_decode <<<"$REQUEST_URI") + declare -a REQUEST_HEADERS while read -r line; do