Made javascript obfuscation of emails even more obfuscatory,

by combining it with entity obfuscation.


git-svn-id: https://pandoc.googlecode.com/svn/trunk@254 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2006-12-20 18:16:07 +00:00
parent 19a81cb504
commit b98edf2c74
3 changed files with 51 additions and 14 deletions

View file

@ -15,9 +15,9 @@ module Text.Pandoc.Writers.HTML (
import Text.Pandoc.Definition
import Text.Pandoc.Shared
import Text.Html ( stringToHtmlString )
import Text.Regex ( mkRegex )
import Text.Regex ( mkRegex, matchRegex )
import Numeric ( showHex )
import Char ( ord )
import Data.Char ( ord, toLower )
import Data.List ( isPrefixOf, partition )
-- | Convert Pandoc document to string in HTML format.
@ -59,14 +59,27 @@ footnoteSection options notes =
-- | Obfuscate a "mailto:" link using Javascript.
obfuscateLink :: WriterOptions -> [Inline] -> String -> String
obfuscateLink options text src =
let text' = inlineListToHtml options text in
let linkText = if src == ("mailto:" ++ text')
then "e"
else "'" ++ text' ++ "'"
altText = if src == ("mailto:" ++ text')
then "\\1 [at] \\2"
else text' ++ " (\\1 [at] \\2)" in
gsub "mailto:([^@]*)@(.*)" ("<script type=\"text/javascript\">h='\\2';n='\\1';e=n+'@'+h;document.write('<a href=\"mailto:'+e+'\">'+" ++ linkText ++ "+'<\\/a>');</script><noscript>" ++ altText ++ "</noscript>") src
let emailRegex = mkRegex "mailto:*([^@]*)@(.*)"
text' = inlineListToHtml options text
src' = map toLower src in
case (matchRegex emailRegex src') of
(Just [name, domain]) ->
let domain' = gsub "\\." " dot " domain
at' = obfuscateChar '@' in
let linkText = if src' == ("mailto:" ++ text')
then "e"
else "'" ++ text' ++ "'"
altText = if src' == ("mailto:" ++ text')
then name ++ " at " ++ domain'
else text' ++ " (" ++ name ++ " at " ++
domain' ++ ")" in
"<script type=\"text/javascript\">\n<!--\nh='" ++
obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
obfuscateString name ++ "';e=n+a+h;\n" ++
"document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\">'+" ++
linkText ++ "+'<\\/'+'a'+'>');\n// -->\n</script><noscript>" ++
obfuscateString altText ++ "</noscript>"
_ -> "<a href=\"" ++ src ++ "\">" ++ text' ++ "</a>" -- malformed email
-- | Obfuscate character as entity.
obfuscateChar :: Char -> String
@ -75,6 +88,10 @@ obfuscateChar char =
let numstr = if even num then (show num) else ("x" ++ (showHex num "")) in
"&#" ++ numstr ++ ";"
-- | Obfuscate string using entities.
obfuscateString :: String -> String
obfuscateString = concatMap obfuscateChar
-- | Escape string, preserving character entities and quote.
stringToHtml :: String -> String
stringToHtml str = escapePreservingRegex stringToHtmlString

View file

@ -415,7 +415,12 @@ Cat &amp; 1 \\ \hline
<p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
<p><a href="/url/" title="title with &quot;quotes&quot; in it">URL and title</a></p>
<p><a href="/url/" title="title with single quotes">URL and title</a></p>
<p><script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+'Email link'+'<\/a>');</script><noscript>Email link (nobody [at] nowhere.net)</noscript></p>
<p><script type="text/javascript">
<!--
h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>');
// -->
</script><noscript>&#x45;&#x6d;&#x61;&#x69;&#108;&#32;&#108;&#x69;&#110;&#x6b;&#32;&#40;&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;&#x29;</noscript></p>
<p><a href="">Empty</a>.</p>
<a id="Reference"></a>
<h2>Reference</h2>
@ -446,7 +451,12 @@ Cat &amp; 1 \\ \hline
<li><a href="http://example.com/">http://example.com/</a></li>
<li>It should.</li>
</ul>
<p>An e-mail address: <script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+e+'<\/a>');</script><noscript>nobody [at] nowhere.net</noscript></p>
<p>An e-mail address: <script type="text/javascript">
<!--
h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
// -->
</script><noscript>&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript></p>
<blockquote>
<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
</blockquote>

View file

@ -415,7 +415,12 @@ Cat &amp; 1 \\ \hline
<p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
<p><a href="/url/" title="title with &quot;quotes&quot; in it">URL and title</a></p>
<p><a href="/url/" title="title with single quotes">URL and title</a></p>
<p><script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+'Email link'+'<\/a>');</script><noscript>Email link (nobody [at] nowhere.net)</noscript></p>
<p><script type="text/javascript">
<!--
h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>');
// -->
</script><noscript>&#x45;&#x6d;&#x61;&#x69;&#108;&#32;&#108;&#x69;&#110;&#x6b;&#32;&#40;&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;&#x29;</noscript></p>
<p><a href="">Empty</a>.</p>
<a id="Reference"></a>
<h2>Reference</h2>
@ -446,7 +451,12 @@ Cat &amp; 1 \\ \hline
<li><a href="http://example.com/">http://example.com/</a></li>
<li>It should.</li>
</ul>
<p>An e-mail address: <script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+e+'<\/a>');</script><noscript>nobody [at] nowhere.net</noscript></p>
<p>An e-mail address: <script type="text/javascript">
<!--
h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
// -->
</script><noscript>&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript></p>
<blockquote>
<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
</blockquote>