[PLUG] Simple Directory Listing to HTML Script
Russell Evans
revans at e-z.net
Tue Nov 19 23:20:04 UTC 2002
I googled HTML escaping because I didn't understand what the issue was. I found
an example CGI and following by example I thought this would work. Does this
cover the issue or are there other characters that break the output? It seems
to deal with <BLINK> correctly.
find $1 | while read filename ; do
htmlfilename=`print $filename | sed -e 's/&/\&/g' -e
's/\"/\"/g' -e 's/>/\>/g' -e 's/</\</g'`
print '<A href="'"$filename"'">'"$htmlfilename"'</A><BR>' |
grep blink >> $output_file
done
On 19 Nov 2002 12:56:26 -0800, Randal L. Schwartz said:
> >>>>> "Cooper" == Cooper Stevenson <cooper at linux-enterprise.net> writes:
>
> Cooper> find $1 | while read file
> Cooper> name
> Cooper> do
> Cooper> print '<A href="'"$filename"'">'"$filename"'</A><BR>' >> $output_file
> Cooper> done
>
> Evil. No HTML escaping.
>
> touch '<blink>'; # ARGGGH!
>
> Better thing in Perl:
>
> use CGI qw(:all :no_debug);
> use File::Find;
> chdir "/web/pic/" or die;
> open STDOUT, ">my_index.html";
> print start_html;
> find sub {
> print a({href => $File::Find::name}, escapeHTML($File::Find::name)), br;
> }, ".";
> print end_html;
>
More information about the PLUG
mailing list