better regex for capturing urls (sensitive to urls in tags) [ci skip]
This commit is contained in:
parent
665517abfc
commit
5e65c88bd8
2 changed files with 11 additions and 2 deletions
|
|
@ -42,8 +42,9 @@ app.views.Content = app.views.StreamObject.extend({
|
|||
}
|
||||
|
||||
function urlify(text) {
|
||||
var urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
|
||||
return text.replace(urlRegex, function(url) {
|
||||
var urlRegex = /(=\s?'|=\s?")?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
|
||||
return text.replace(urlRegex, function(url, preceeder) {
|
||||
if(preceeder) return url
|
||||
var protocol = (url.search(/:\/\//) == -1 ? "http://" : "")
|
||||
return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>"
|
||||
})
|
||||
|
|
|
|||
|
|
@ -141,6 +141,14 @@ describe("app.views.Post", function(){
|
|||
expect(view.$("a[href='" + link + "']").text()).toContain(link)
|
||||
})
|
||||
})
|
||||
|
||||
it("doesn't create link tags for links that are already in <a/> or <img/> tags", function(){
|
||||
link = "http://google.com"
|
||||
|
||||
this.statusMessage.set({text : ""})
|
||||
var view = new app.views.Content({model : this.statusMessage})
|
||||
expect(view.presenter().text).toNotContain('</a>')
|
||||
})
|
||||
})
|
||||
|
||||
context("user not signed in", function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue