X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=cgi.sh;h=30e6d769015d74ce4dc645e5225f148272d6836e;hp=7ff73d0ca4c8effe4b1df85c851b38d3e902f6ec;hb=ee25e0e34ad0a47e2d2aad17b070ed7474f4c571;hpb=3c2a130cdaeadf1a67eb37ab70a298fa756a3c01 diff --git a/cgi.sh b/cgi.sh index 7ff73d0..30e6d76 100755 --- a/cgi.sh +++ b/cgi.sh @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with shcgi. If not, see . +unset _GET _POST _REF _COOKIE declare -A _GET declare -A _POST declare -A _REF @@ -33,10 +34,12 @@ printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do debug "_GET[$key] => $val" done -if [ "$REQUEST_METHOD" = POST ]; then +if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=$CONTENT_LENGTH}" -gt 0 ]; then # parse HTTP POST string debug "== CGI DATA: POST ==" - sed -u 1q |tr '&' '\n' |while read query; do + head -c "$HTTP_CONTENT_LENGTH" \ + | sed -un 's;&;\n;g; p; q' \ + | while read query; do key="$(printf %s "$query" |sed -r 's:^([\.a-zA-Z0-9_-]+)=(.*)$:\1:')" val="$(printf %s "$query" |sed -r 's:^([\.a-zA-Z0-9_-]+)=(.*)$:\2:')" value="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")" @@ -108,7 +111,8 @@ attribsafe(){ # except alphanumerig ascii printf %s "$*" \ - | hexdump -v -e '/1 "&#x%02X;"' \ + | iconv -f utf-8 -t utf32le \ + | hexdump -v -e '/4 "&#x%02X;"' \ | sed 's;0\;;0;g; s;1\;;1;g; s;2\;;2;g; s;3\;;3;g; s;4\;;4;g; s;5\;;5;g; s;6\;;6;g; s;7\;;7;g; s;8\;;8;g; s;9\;;9;g; s;A\;;A;g; s;B\;;B;g; s;C\;;C;g; s;D\;;D;g; s;E\;;E;g; s;F\;;F;g; @@ -124,7 +128,7 @@ attribsafe(){ } redirect(){ - printf '%s\n\n' "Location: $*" + printf '%s\r\n\r\n' "Location: $*" exit 0 } @@ -139,5 +143,5 @@ set_cookie(){ printf 'Set-Cookie: %s' "$cookie" [ -n "$expire" ] && printf '; Expires=%s' "$expire" [ $# -ge 3 ] && shift 2 && printf '; %s' "$@" - printf '\n' + printf '\r\n' }