Re: [dev] [sw] Suckless web-framework

From: Nibble <nibble.ds_AT_gmail.com>
Date: Sun, 4 Apr 2010 11:33:46 +0200

Hi,

First, thanks for the feedback :) Let's comment some of your points

> This code is horrible

Thanks to mails like yours I'll try to improve it. Take into account
that it is the very first version.

> # grep thinks the second argument is a file
> > BL="^index.md$ ^images$" # Black list
> BL="^index.md$\|^images$" # Black list

Wrong, take a look at this line:
BL=`echo ${BL} | sed -e "s/\( \+\|^\)/ -e /g"`

> # Two expensive subshells... not to mention testing for zero/non-zero
> # length string is redundant when grep's $? is enough
> > if [ -z "`echo ${REQUEST_URI} | grep -F "${BIN}"`" ] || \
> > [ -n "`echo ${REQUEST_URI} | grep "[^a-zA-Z0-9_\./ ]\+"`" ]; then
> echo "$REQUEST_URI" | if grep -Fvq "$BIN" || grep -q '[[:alnum:]_\./
> ]\+'; then
> > echo "<script>window.location=\"${BIN}\";</script>"
> > exit 1
> > fi

I also have to look for special characters to avoid non-desirable
behaviors ;)

> # echo | blah is becoming rampant; let's not ignore it this time
> > QUERY=`echo ${REQUEST_URI} | sed -e "s,.*${BIN}/*\(.*\),\1,"`
> QUERY=`sed "s,.*$BIN/*\(.*\),\1," <<-!
> $REQUEST_URI
> !

So, it is better to use 3 loc for this?
 
> # Why heredoc instead of subshell?
> # Compare: time for i in `seq 1 1000`; do echo str | grep pattern
> >/dev/null; done
> # ...with: time for i in `seq 1 1000`; do grep pattern >/dev/null <<-!
> # str
> # !
> # heredocs can also contain subshells... you save one
> # from `cmd | cmd`
> > DIR=`dirname ${QUERY} | sed -e "s,/*$,,"`>
> > # done

I see, this is a more interesting argument for using heredocs. But,
just a question (because I don't really know) is heredocs as standard as
a plain "echo blah | cmd" ?

> # Please don't use ls in scripts -- make them newline/special
> char # friendly. Also, it's quite possible that BL has characters
> # that the shell can misinterpret. Quote it.

BL is parsed... obviously the user could enter the list in a wrong
format, although, to separate patterns by spaces is not that
difficult... (I guess)

Kind regards,
-- nibble
Received on Sun Apr 04 2010 - 09:33:46 UTC

This archive was generated by hypermail 2.2.0 : Sun Apr 04 2010 - 09:36:02 UTC