From 8b63e320442e836b84c7203c4308c848e8b110a5 Mon Sep 17 00:00:00 2001 From: Claudio Perez Gamayo Date: Sat, 26 Mar 2011 09:47:07 +0100 Subject: [PATCH] Fix issue with hastag parsing (https://github.com/hotsh/rstat.us/issues/#issue/66) --- models/update.rb | 8 +++++--- test/update_test.rb | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/models/update.rb b/models/update.rb index d5d1559b..144b4861 100644 --- a/models/update.rb +++ b/models/update.rb @@ -13,7 +13,7 @@ class Update key :remote_url key :referral_id - + def referral Update.first(:id => referral_id) end @@ -31,7 +31,7 @@ def to_html # we let almost anything be in a username, except those that mess with urls. but you can't end in a .:;, or ! #also ignore container chars [] () "" '' {} - # XXX: the _correct_ solution will be to use an email validator + # XXX: the _correct_ solution will be to use an email validator out.gsub!(/(^|[ \t\n\r\f"'\(\[{]+)@([^ \t\n\r\f&?=@%\/\#]*[^ \t\n\r\f&?=@%\/\#.!:;,"'\]}\)])/) do |match| if u = User.first(:username => /^#{$2}$/i) "#{$1}@#{$2}" @@ -40,7 +40,9 @@ def to_html end end out.gsub!(/(http[s]?:\/\/\S+[a-zA-Z0-9\/])/, "\\1") - out.gsub!(/#(\w+)/, "#\\1") + out.gsub!(/(^|\s+)#(\w+)/) do |match| + "#{$1}##{$2}" + end out end diff --git a/test/update_test.rb b/test/update_test.rb index 1e570987..eaa66574 100644 --- a/test/update_test.rb +++ b/test/update_test.rb @@ -30,11 +30,15 @@ def test_at_replies def test_links u = Update.new(:text => "This is a message mentioning http://rstat.us/.") assert_match /http:\/\/rstat.us\/<\/a>/, u.to_html + u = Update.new(:text => "https://github.com/hotsh/rstat.us/issues#issue/11") + assert_equal "https://github.com/hotsh/rstat.us/issues#issue/11", u.to_html end def test_hashtags u = Update.new(:text => "This is a message with a #hashtag.") assert_match /#hashtag<\/a>/, u.to_html + u = Update.new(:text => "This is a message with a#hashtag.") + assert_equal "This is a message with a#hashtag.", u.to_html end end