|
cgiparse Korn Shell 93 function to parse CGI variables
containing encoded HEX characters.
################################################################
####
#### Program: cgiparse
####
#### Description: Korn Shell 93 function to parse CGI variables
#### containing encoded HEX characters. Initializes CGI
#### variables with their assigned values into the current
#### shell environment. If no CGI variable is passed, then
#### the parsed CGI string is sent to standard output.
####
#### Description: Version 0.2
####
#### Author: Dana French (dfrench@mtxia.com)
#### 615.556.0456
####
#### Date: 20061024
####
#### Usage:
####
#### IFS="&" PARSED=( ${QUERY_STRING} )
#### for VAR in "${PARSED[@]}"
#### do
#### print "${VAR}" | cgiparse
#### done
####
################################################################
function cgiparse_k93
{
typeset CGILINE
typeset CGITMP
typeset CGIVAR
typeset CGIVAL
CGIIFS="${IFS}"
IFS=''
while read -r -- CGILINE
do
CGITMP="${CGILINE//+/ }"
CGITMP="${CGITMP//%([A-Za-z0-9][A-Za-z0-9])/\$( printf "'\\\0%o'" 0x\1 )}"
CGIVAR="${CGITMP%%=*}"
CGIVAL="${CGITMP#*=}"
CGITMP="${CGIVAR}=\"\\\"${CGIVAL}\\\"\""
[[ "${CGITMP}" = *=* ]] &&
eval $( eval print -- "${CGITMP}" ) ||
eval print -- "${CGITMP}"
done
IFS="${CGIIFS}"
}
################################################################
|
|
|