From a1cf2792266e81cf6d378b3bb5f05e5c8331824e Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Sun, 8 Jan 2012 17:35:29 -0800
Subject: [PATCH] support twitter hashbangs in urls for url parsing [ci skip]

---
 public/javascripts/app/views/content_view.js | 4 ++--
 spec/javascripts/app/views/post_view_spec.js | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/public/javascripts/app/views/content_view.js b/public/javascripts/app/views/content_view.js
index fc7541ba41..df70f90700 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 569b8ca8b5..0f7a146780 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"
 
-- 
GitLab