Skip to content
Extraits de code Groupes Projets
Valider 1a94a24f rédigé par Florian Staudacher's avatar Florian Staudacher
Parcourir les fichiers

fix autolinking links that start with just www... and not a complete http://...

(fixes #3468)
parent fb9da740
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
// process links // process links
// regex copied from: https://code.google.com/p/pagedown/source/browse/Markdown.Converter.js#1198 (and slightly expanded) // regex copied from: https://code.google.com/p/pagedown/source/browse/Markdown.Converter.js#1198 (and slightly expanded)
var linkRegex = /(\[.*\]:\s)?(<|\()((https?|ftp):\/\/[^\/'">\s][^'">\s]+?)(>|\))/gi; var linkRegex = /(\[.*\]:\s)?(<|\()((?:(https?|ftp):\/\/[^\/'">\s]|www)[^'">\s]+?)(>|\))/gi;
text = text.replace(linkRegex, function() { text = text.replace(linkRegex, function() {
var unicodeUrl = arguments[3]; var unicodeUrl = arguments[3];
unicodeUrl = ( unicodeUrl.match(/^www/) ) ? ('http://' + unicodeUrl) : unicodeUrl;
var addr = parse_url(unicodeUrl); var addr = parse_url(unicodeUrl);
if( !addr.host ) addr.host = ""; // must not be 'undefined' if( !addr.host ) addr.host = ""; // must not be 'undefined'
......
...@@ -26,11 +26,16 @@ describe("app.helpers.textFormatter", function(){ ...@@ -26,11 +26,16 @@ describe("app.helpers.textFormatter", function(){
// This test will fail if our join is just (" ") -- an edge case that should be addressed. // This test will fail if our join is just (" ") -- an edge case that should be addressed.
it("autolinks", function(){ it("autolinks", function(){
var links = ["http://google.com", var links = [
"http://google.com",
"https://joindiaspora.com", "https://joindiaspora.com",
"http://www.yahooligans.com", "http://www.yahooligans.com",
"http://obama.com", "http://obama.com",
"http://japan.co.jp"] "http://japan.co.jp",
"www.mygreat-example-website.de",
"www.jenseitsderfenster.de", // from issue #3468
"www.google.com"
];
// The join that would make this particular test fail: // The join that would make this particular test fail:
// //
...@@ -40,7 +45,7 @@ describe("app.helpers.textFormatter", function(){ ...@@ -40,7 +45,7 @@ describe("app.helpers.textFormatter", function(){
var wrapper = $("<div>").html(formattedText); var wrapper = $("<div>").html(formattedText);
_.each(links, function(link) { _.each(links, function(link) {
var linkElement = wrapper.find("a[href='" + link + "']"); var linkElement = wrapper.find("a[href*='" + link + "']");
expect(linkElement.text()).toContain(link); expect(linkElement.text()).toContain(link);
expect(linkElement.attr("target")).toContain("_blank"); expect(linkElement.attr("target")).toContain("_blank");
}) })
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter