also handle images and links without sub-domain
This commit is contained in:
parent
c5139c9a71
commit
49801644cc
2 changed files with 17 additions and 6 deletions
|
|
@ -23,13 +23,14 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// process links
|
// process links
|
||||||
var linkRegex = /(\[.*\]:\s)?(<|\()((https?|ftp):[^'">\s]+)(>|\))/gi;
|
var linkRegex = /(\[.*\]:\s)?(<|\()(((https?|ftp):\/{1,3})([^'">\s]+))(>|\))/gi;
|
||||||
text = text.replace(linkRegex, function() {
|
text = text.replace(linkRegex, function() {
|
||||||
var unicodeUrl = arguments[3];
|
var protocol = arguments[4];
|
||||||
var asciiUrl = punycode.toASCII(unicodeUrl);
|
var unicodeUrl = arguments[6];
|
||||||
|
var asciiUrl = protocol+punycode.toASCII(unicodeUrl);
|
||||||
if(arguments[1] == "") { // inline link
|
if(arguments[1] == "") { // inline link
|
||||||
if(arguments[2] == "<") return "["+unicodeUrl+"]("+asciiUrl+")"; // without link text
|
if(arguments[2] == "<") return "["+protocol+unicodeUrl+"]("+asciiUrl+")"; // without link text
|
||||||
else return arguments[2]+asciiUrl+arguments[5]; // with link text
|
else return arguments[2]+asciiUrl+arguments[7]; // with link text
|
||||||
} else { // reference style link
|
} else { // reference style link
|
||||||
return arguments[1]+asciiUrl;
|
return arguments[1]+asciiUrl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,18 @@ describe("app.views.Post", function(){
|
||||||
var view = new app.views.Post({model: this.statusMessage}).render();
|
var view = new app.views.Post({model: this.statusMessage}).render();
|
||||||
|
|
||||||
expect($(view.el).html()).not.toContain(this.evilUrl);
|
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 = "";
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue