X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=cgilite.sh;fp=cgilite.sh;h=f03f74732165e4d672418d3718ecc228db4ac53d;hp=b7067a70ae2fd95bb84e70cc89d43f2441d56173;hb=b8cec2270b5917e96f57d72c4d1ad96471cad3d3;hpb=4a73c7164a28728de0b717e869704c803ef9ca65 diff --git a/cgilite.sh b/cgilite.sh index b7067a7..f03f747 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -187,6 +187,8 @@ COOKIE(){ } HTML(){ + # Escape HTML cahracters + # Also escape [, ], and \n for use in html-sh local str out [ $# -eq 0 ] && str="$(cat)" || str="$*" while [ "$str" ]; do @@ -196,6 +198,9 @@ HTML(){ \>*) out="${out}>";; \"*) out="${out}"";; \'*) out="${out}'";; + \[*) out="${out}[";; + \]*) out="${out}]";; + "${BR}"*) out="${out} ";; *) out="${out}${str%"${str#?}"}";; esac str="${str#?}" @@ -204,6 +209,7 @@ HTML(){ } URL(){ + # Escape pathes, so they can be used in link tags and HTTP Headers local str out [ $# -eq 0 ] && str="$(cat)" || str="$*" while [ "$str" ]; do @@ -213,6 +219,10 @@ URL(){ \'*) out="${out}%27";; \?*) out="${out}%3F";; \#*) out="${out}%23";; + \[*) out="${out}%5B";; + \]*) out="${out}%5D";; + \ *) out="${out}%20";; + "${BR}"*) out="${out}%0A";; %*) out="${out}%25";; *) out="${out}${str%"${str#?}"}";; esac