also handle images and links without sub-domain

This commit is contained in:
Florian Staudacher 2012-03-24 02:57:32 +01:00
parent c5139c9a71
commit 49801644cc
2 changed files with 17 additions and 6 deletions

View file

@ -23,13 +23,14 @@
});
// process links
var linkRegex = /(\[.*\]:\s)?(<|\()((https?|ftp):[^'">\s]+)(>|\))/gi;
var linkRegex = /(\[.*\]:\s)?(<|\()(((https?|ftp):\/{1,3})([^'">\s]+))(>|\))/gi;
text = text.replace(linkRegex, function() {
var unicodeUrl = arguments[3];
var asciiUrl = punycode.toASCII(unicodeUrl);
var protocol = arguments[4];
var unicodeUrl = arguments[6];
var asciiUrl = protocol+punycode.toASCII(unicodeUrl);
if(arguments[1] == "") { // inline link
if(arguments[2] == "<") return "["+unicodeUrl+"]("+asciiUrl+")"; // without link text
else return arguments[2]+asciiUrl+arguments[5]; // with link text
if(arguments[2] == "<") return "["+protocol+unicodeUrl+"]("+asciiUrl+")"; // without link text
else return arguments[2]+asciiUrl+arguments[7]; // with link text
} else { // reference style link
return arguments[1]+asciiUrl;
}

View file

@ -171,8 +171,18 @@ describe("app.views.Post", function(){
var view = new app.views.Post({model: this.statusMessage}).render();
expect($(view.el).html()).not.toContain(this.evilUrl);
expect($(view.el).html()).toContain(this.asciiUrl);
});
});
it("correctly handles images with non-ascii urls", function() {
var postContent = "![logo](http://bündnis-für-krankenhäuser.de/wp-content/uploads/2011/11/cropped-logohp.jpg)";
var niceImg = '"http://xn--bndnis-fr-krankenhuser-i5b27cha.de/wp-content/uploads/2011/11/cropped-logohp.jpg"';
this.statusMessage.set({text: postContent});
var view = new app.views.Post({model: this.statusMessage}).render();
expect($(view.el).html()).toContain(niceImg);
});
});
})
});