Browse Source

fix(simpleautolink): fix mail simpleAutoLink to ignore urls with @ symbol

Urls with @ symbol will not be incorrectly converted to mail addressed

Closes #204
Estevão Soares dos Santos 9 years ago
parent
commit
8ebb25e486

+ 2 - 2
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 27-08-2015 */
+;/*! showdown 07-10-2015 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -996,7 +996,7 @@ showdown.subParser('autoLinks', function (text, options) {
 
   var simpleURLRegex  = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
       delimUrlRegex   = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
-      simpleMailRegex = /\b(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)\b/gi,
+      simpleMailRegex = /(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/gi,
       delimMailRegex  = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
 
   text = text.replace(delimUrlRegex, '<a href=\"$1\">$1</a>');

File diff suppressed because it is too large
+ 0 - 0
dist/showdown.js.map


File diff suppressed because it is too large
+ 1 - 1
dist/showdown.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
src/subParsers/autoLinks.js

@@ -5,7 +5,7 @@ showdown.subParser('autoLinks', function (text, options) {
 
   var simpleURLRegex  = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
       delimUrlRegex   = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
-      simpleMailRegex = /\b(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)\b/gi,
+      simpleMailRegex = /(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/gi,
       delimMailRegex  = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
 
   text = text.replace(delimUrlRegex, '<a href=\"$1\">$1</a>');

+ 7 - 0
test/features/#204.certain-links-with-at-and-dot-break-url.html

@@ -0,0 +1,7 @@
+<p><a href="http://website.com/img@x2.jpg">http://website.com/img@x2.jpg</a></p>
+
+<p><a href="http://website.com/img-x2.jpg">http://website.com/img-x2.jpg</a></p>
+
+<p><a href="http://website.com/img@x2">http://website.com/img@x2</a></p>
+
+<p><a href="http://website.com/img@.jpg">http://website.com/img@.jpg</a></p>

+ 7 - 0
test/features/#204.certain-links-with-at-and-dot-break-url.md

@@ -0,0 +1,7 @@
+http://website.com/img@x2.jpg
+
+http://website.com/img-x2.jpg
+
+http://website.com/img@x2
+
+http://website.com/img@.jpg

+ 1 - 1
test/node/testsuite.features.js

@@ -15,7 +15,7 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({parseImgDimensions: true});
     } else if (testsuite[i].name === '#69.header_level_start') {
       converter = new showdown.Converter({headerLevelStart: 3});
-    } else if (testsuite[i].name === '#164.1.simple_autolink') {
+    } else if (testsuite[i].name === '#164.1.simple_autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
       converter = new showdown.Converter({simplifiedAutoLink: true});
     } else if (testsuite[i].name === '#164.2.disallow_underscore_emphasis_mid_word') {
       converter = new showdown.Converter({literalMidWordUnderscores: true});

Some files were not shown because too many files changed in this diff