From 90c52b83e74275a82d2b16d64b9ef4715eaa799d Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Fri, 27 Jan 2017 19:03:37 +0000 Subject: [PATCH] feat(encodeEmail): add option to enable/disable mail obfuscation Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding. This option makes it possible to disable this. --- README.md | 3 ++ dist/showdown.js | Bin 75601 -> 75466 bytes dist/showdown.js.map | Bin 222377 -> 221733 bytes dist/showdown.min.js | Bin 30745 -> 30945 bytes dist/showdown.min.js.map | Bin 33899 -> 33987 bytes src/helpers.js | 40 +++++++++++++++++ src/options.js | 5 +++ src/subParsers/autoLinks.js | 11 ++++- src/subParsers/encodeEmailAddress.js | 52 ---------------------- test/features/disable-email-encoding.html | 1 + test/features/disable-email-encoding.md | 1 + test/node/showdown.helpers.js | 30 +++++++++++++ test/node/testsuite.features.js | 2 + 13 files changed, 91 insertions(+), 54 deletions(-) delete mode 100644 src/subParsers/encodeEmailAddress.js create mode 100644 test/features/disable-email-encoding.html create mode 100644 test/features/disable-email-encoding.md create mode 100644 test/node/showdown.helpers.js diff --git a/README.md b/README.md index 3c9630a..8ab5dc1 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,9 @@ var defaultOptions = showdown.getDefaultOptions(); * **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned (since v1.6.0) + * **encodeEmails**: (boolean) [default true] Enables e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities. (since v1.6.1) + + NOTE: Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding. **NOTE**: Please note that until version 1.6.0, all of these options are ***DISABLED*** by default in the cli tool. diff --git a/dist/showdown.js b/dist/showdown.js index 52fb0da37792d6210e3d84b33596eb68965e123c..8b7e44d3453478189fd62f6687ea53baba63ec36 100644 GIT binary patch delta 783 zcma))v2PPG6vhWa6J1hNRj5%@QN0w2OH0$VEJd`5T2&dcz|gks)^z33GNZ5Ibpw>N--KoBX31QiLMb|bS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down.min.js index 798230df580fb8bb22dad578609ab95658b36b49..dde42109d662bf03a6a418850ec9fc6aa0410e80 100644 GIT binary patch delta 441 zcmaKnJxc>Y5QYg@NKn!k5Ve>b!sWa(kq8QBE*g?6Qj1n1th;l$#mjEo-Ajrf!P3^N zwDK=Vevz$>AElK^svu}JQ#|i8^FDs$UO#h%>P`uCEQd@E1=J2-3SY}(4+WJB!ye&@ z_D2jOk|ySyBq{o(J&&QLiuVnd!neXX3b;FifiR{}Yt&$3CDU#^od~H$kP)b>I5r>U%$L~Qr5q!|mZVu-mRL0TzqvY7 zlIG-tp`sG0dCB=Hsjj(+nK_OrDMhKp#Y&nQ$(ps38)GFW|FPoQe8}PhuONn^$rGKW zC&zQKP0m+p=TQRbF3Go2(oWQw{6#5%M(bhImbFz!Fi-k_2t-4L3LPk+) ynyr$$cA~brk{yUrve8epQv%8+>J_CH1kW(r|W=}Y+m5zXaoR6MMx9? diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 5e2077fbe5c6eb30c1128aee2e6569af7215d81f..70c1a54aa3228c0b5b4c94bab24114a7f50d32ea 100644 GIT binary patch delta 9260 zcmb_idu&_Rd509&k)6h}BgwX6%T63ewnI83MNt$J$M(4ol2_OC6-Ch$mBfxLF?@*P zQ=%v(jk;{X+7)e)od7M0ZbPu4*fU8X1jR6*NHOdI6ieG-=wn!m0DGXr3Uuoq!y2r^ ze&2U4Wyz9(bl5+X?>XQ3&i8&D|J$d!|NPV4@5H(v$W`X63psOXu2|mGyT7(?aNB}d zSZL&$%`@IJv@KsacyaT?{eRrOuh7W7DF5`p?{0qf;PCwi&8fQPofo>>-Jmn zD@V?r8_~Q8A#9y~6NcBuzfEsih;&Hv#)MhXy_OKxnEa0;NA(CT={JPe6e8!*ygB@# zBYHtMXwA~GFC2goz&Jq*8+hhK40s%DjmU|I9zBE)?Bod9y5`wjd+4pMLjj^7R-oUg zSd)()dtA=;KQNDFkmPt%LJyg1npYRGX{KnMu{(a9FLuFpeA%NqZq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XM^#3q4d7{HF!|7QQ*g$cT;??q$Vuj3OQu8_+l+34jBY}JI zHq<&172Bbk$fw}L=_xTQIdraoxK36(BOiResH)ZBG*!F@YE2YKCF)Op@A+}3TIHyR zW(2Gk_E)QKX6`?G00H&62C4Vm4B1_axX?LJfx%2fHa)foAQ-jS{rpfHx=-pJX1)wN&pg&G24{CQFy;&Qrhc74@~R%#&uFr$fzstAXm{Nc{#f=eu}Z7Qz6+C@ZX(7FO`gk@LhaR$1gZ1WVloAd#zM%!K_ z%luO5b!X803(ce85|nZJ7oC|?DO8ZJR=zn3 zqS;Go9TCMtd%d6^lOtJSA^RQ=@?Oy!9DdUf;?2Ki8KtM+Wh3EV~>hqMpdQF3(3 z6K4}4A}LIdzATT_e$csP%H_u3Ve=_W&>@JPy2~j#C)=u`g1lZo+vA|;8g|iZ$zQ8~ z(BApZa4hldk0sPRA2!R7|4vzBh*fYZZZDX29G7PuIrwcSeHzI5D*5-^8<49wN zPB$@}gaD7FM&%px51do+0--)dZDUMax13fB4}_RV=nHsNgC>=~4BsPg!md4zg+05~ z#{>)=lqPEI5}@ARD)%{2%D}B?0w^{3OgX--?W}Wod{}9a;h2{SlH*u#yC|j$>_qLw z07_J+Al-YgfZ-*b9NucNiHo|1XH~?NU}%CEG}WxJb2%t~x_uUpQ^#Hy9Bg1X574TX zqY<{i`wODxw(gVSg}#mnx$wfWV}o4rKzvm3_;gb6uV#}myh33t7}V<#dG)0!Ma4aneVmj1&$b@f L{nM9zspG!@keMH; diff --git a/src/helpers.js b/src/helpers.js index fb21348..d572df4 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -251,6 +251,46 @@ showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right return finalStr; }; +/** + * Obfuscate an e-mail address through the use of Character Entities, + * transforming ASCII characters into their equivalent decimal or hex entities. + * + * Since it has a random component, subsequent calls to this function produce different results + * + * @param {string} mail + * @returns {string} + */ +showdown.helper.encodeEmailAddress = function (mail) { + 'use strict'; + var encode = [ + function (ch) { + return '&#' + ch.charCodeAt(0) + ';'; + }, + function (ch) { + return '&#x' + ch.charCodeAt(0).toString(16) + ';'; + }, + function (ch) { + return ch; + } + ]; + + mail = mail.replace(/./g, function (ch) { + if (ch === '@') { + // this *must* be encoded. I insist. + ch = encode[Math.floor(Math.random() * 2)](ch); + } else { + var r = Math.random(); + // roughly 10% raw, 45% hex, 45% dec + ch = ( + r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch) + ); + } + return ch; + }); + + return mail; +}; + /** * POLYFILLS */ diff --git a/src/options.js b/src/options.js index e9d7008..87705f8 100644 --- a/src/options.js +++ b/src/options.js @@ -105,6 +105,11 @@ function getDefaultOpts(simple) { defaultValue: false, description: 'Enables github @mentions', type: 'boolean' + }, + encodeEmails: { + defaultValue: true, + description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities', + type: 'boolean' } }; if (simple === false) { diff --git a/src/subParsers/autoLinks.js b/src/subParsers/autoLinks.js index 0d5583d..4bf53e9 100644 --- a/src/subParsers/autoLinks.js +++ b/src/subParsers/autoLinks.js @@ -36,8 +36,15 @@ showdown.subParser('autoLinks', function (text, options, globals) { } function replaceMail(wholeMatch, mail) { - var unescapedStr = showdown.subParser('unescapeSpecialChars')(mail); - return showdown.subParser('encodeEmailAddress')(unescapedStr); + var href = 'mailto:'; + mail = showdown.subParser('unescapeSpecialChars')(mail); + if (options.encodeEmails) { + mail = showdown.helper.encodeEmailAddress(mail); + href = showdown.helper.encodeEmailAddress(href + mail); + } else { + href = href + mail; + } + return '' + mail + ''; } text = globals.converter._dispatch('autoLinks.after', text, options, globals); diff --git a/src/subParsers/encodeEmailAddress.js b/src/subParsers/encodeEmailAddress.js deleted file mode 100644 index 925b3cc..0000000 --- a/src/subParsers/encodeEmailAddress.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Input: an email address, e.g. "foo@example.com" - * - * Output: the email address as a mailto link, with each character - * of the address encoded as either a decimal or hex entity, in - * the hopes of foiling most address harvesting spam bots. E.g.: - * - * foo - * @example.com - * - * Based on a filter by Matthew Wickline, posted to the BBEdit-Talk - * mailing list: - * - */ -showdown.subParser('encodeEmailAddress', function (addr) { - 'use strict'; - - var encode = [ - function (ch) { - return '&#' + ch.charCodeAt(0) + ';'; - }, - function (ch) { - return '&#x' + ch.charCodeAt(0).toString(16) + ';'; - }, - function (ch) { - return ch; - } - ]; - - addr = 'mailto:' + addr; - - addr = addr.replace(/./g, function (ch) { - if (ch === '@') { - // this *must* be encoded. I insist. - ch = encode[Math.floor(Math.random() * 2)](ch); - } else if (ch !== ':') { - // leave ':' alone (to spot mailto: later) - var r = Math.random(); - // roughly 10% raw, 45% hex, 45% dec - ch = ( - r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch) - ); - } - return ch; - }); - - addr = '' + addr + ''; - addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part - - return addr; -}); diff --git a/test/features/disable-email-encoding.html b/test/features/disable-email-encoding.html new file mode 100644 index 0000000..21e2731 --- /dev/null +++ b/test/features/disable-email-encoding.html @@ -0,0 +1 @@ +

this email foobar@example.com should not be encoded

diff --git a/test/features/disable-email-encoding.md b/test/features/disable-email-encoding.md new file mode 100644 index 0000000..80fb6e8 --- /dev/null +++ b/test/features/disable-email-encoding.md @@ -0,0 +1 @@ +this email should not be encoded diff --git a/test/node/showdown.helpers.js b/test/node/showdown.helpers.js new file mode 100644 index 0000000..ec9fa21 --- /dev/null +++ b/test/node/showdown.helpers.js @@ -0,0 +1,30 @@ +/** + * Created by Estevao on 27/01/2017. + */ + +var bootstrap = require('../bootstrap.js'), + showdown = bootstrap.showdown, + encoder = showdown.helper.encodeEmailAddress; + +describe('encodeEmailAddress', function () { + 'use strict'; + var email = 'foobar@example.com', + encodedEmail = encoder(email); + + it('should encode email', function () { + encodedEmail.should.not.equal(email); + }); + + it('should decode to original email', function () { + var decodedEmail = encodedEmail.replace(/&#(.+?);/g, function (wm, cc) { + if (cc.charAt(0) === 'x') { + //hex + return String.fromCharCode('0' + cc); + } else { + //dec + return String.fromCharCode(cc); + } + }); + decodedEmail.should.equal(email); + }); +}); diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index c25aa6a..f2bccc0 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -53,6 +53,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({ghCompatibleHeaderId: true}); } else if (testsuite[i].name === 'ghMentions') { converter = new showdown.Converter({ghMentions: true}); + } else if (testsuite[i].name === 'disable-email-encoding') { + converter = new showdown.Converter({encodeEmails: false}); } else { converter = new showdown.Converter(); }