diff --git a/public/javascripts/app/views/content_view.js b/public/javascripts/app/views/content_view.js index fc7541ba419fe78db798c9a5dcfdb0bfdd6de464..df70f90700352d56477608495e86456ec42a1fe4 100644 --- a/public/javascripts/app/views/content_view.js +++ b/public/javascripts/app/views/content_view.js @@ -42,8 +42,8 @@ app.views.Content = app.views.StreamObject.extend({ } function urlify(text) { - 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) { + 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, bang) { if(preceeder) return url var protocol = (url.search(/:\/\//) == -1 ? "http://" : "") return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>" diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 569b8ca8b52c99f66c0a05912ce321c8ffcc7dea..0f7a146780c8aa557b3e24198652caa76df9147a 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -142,6 +142,14 @@ describe("app.views.Post", function(){ }) }) + it("works with urls that use #! syntax (i'm looking at you, twitter)')", function(){ + link = "http://twitter.com/#!/hashbangs?gross=true" + this.statusMessage.set({text : link}) + var view = new app.views.Post({model : this.statusMessage}).render(); + + 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"