Commit ad62b0d3 authored by Krayon's avatar Krayon

Harden URL parsing

Tested on the following input:

This is a test containing http and https and the like
ftp://example and
Also, httpgrumpy is a cool thing
parent a9dc85ad
......@@ -38,10 +38,14 @@ echo "<!DOCTYPE HTML>
<p>" > "${OUTFILE}"
perl -pe 's/&/&amp;/g;' -pe 's/"/&quot;/g;' -pe "s/'/&apos;/g;" -pe 's/</&lt;/g;' -pe 's/>/&gt;/g;' -pe 's/(http.*)\s/<a href="\1">\1<\/a>/;' -pe 's/^(.*)$/\1<br \/>/;' "${INFILE}" >> "${OUTFILE}"
# NOTE: The matching of '$' as well as '\s' is required for URLs that are at
# the end of the file without a EOL.
perl -pe 's/&/&amp;/g;' -pe 's/"/&quot;/g;' -pe "s/'/&apos;/g;" \
-pe 's/</&lt;/g;' -pe 's/>/&gt;/g;' \
-pe 's/(http|ftp)(s?:\/\/[^(\s|$)]*)/<a href="\1\2">\1\2<\/a>/g;' \
-pe 's/$/\1<br \/>/;' "${INFILE}" >> "${OUTFILE}"
echo '
echo '</p>
' >> "${OUTFILE}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment