Commit edd19b5886d88b87ffa233a3196ca399c5b4268f

  • Tree SHA1: 4b52050
  • Parent SHA1: 01b5bc4 (Don't load jquery or our custom javascript code when viewing an in-reply-to link (it screws up scrollTo on the timeline page, among other things).)
  • raw diff | raw patch
Write tests for the hashtag identification code. Rewrite the hashtag identification regexp. Tweak slightly the URI identification regexp.
  
6565 # XXX: + also breaks it
6666
6767 # maybe laconica-0.7.3/lib/util.php:common_replace_urls_callback() ?
68 new.gsub!(/(https?:\/\/([a-zA-Z0-9_%\-+?#\/]|\.(?!\z|\W))+)/, '<a href="
68 new.gsub!(/(https?:\/\/([a-zA-Z0-9_%\-+?#\/]|\.(?!\z|\s))+)/, '<a href="
6969 new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>')
7070 return new
7171end
8282 # turns #whatever: into #<link>whatever:</link>
8383
8484 # hashtag regexp in laconica is /(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/
85 new.gsub!(/#((?!39;)\S+)/, '#<a href="http://identi.ca/tag/">
85 # #YouTwitFace." breaks it.
86 # text is: Conan's #Tonight_Show: "In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace."
87
88 new.gsub!(/(^|\s)#(?:(?!39;)([A-Za-z0-9_\-]+|\.(?!\z|\s)))/, '\1#<a href="http://identi.ca/tag/\2">\2</a>')
8689
8790 # group regexp in laconica is /(?:^|\s)!([A-Za-z0-9]{1,64})
8891 new.gsub!(/(?:!(\S+))/, '!<a href="http://identi.ca/group/\1">\1</a>')
  
8888 make_user_link(@identica)
8989 end
9090 end
91
92 context "when parsing text from identica" do
93
94 should "correctly parse hashtags" do
95 assert_equal %q(#<a href="http://identi.ca/tag/hashtag">hashtag</a>),
96 identicaify("#hashtag")
97 end
98
99 should "correctly parse hashtags with leading words" do
100 assert_equal %q(whatever #<a href="http://identi.ca/tag/hashtag">hashtag</a>),
101 identicaify("whatever #hashtag")
102 end
103
104 should "correctly parse hashtags with trailing words" do
105 assert_equal %q(#<a href="http://identi.ca/tag/hashtag">hashtag</a> whatever),
106 identicaify("#hashtag whatever")
107 end
108
109 should "correctly parse hashtags with leading and trailing words" do
110 assert_equal %q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a> whatever),
111 identicaify("leading #hashtag whatever")
112 end
113
114 ['.', ',', '#', '?'].each do |char|
115 should "correctly parse hashtags with the character #{char} at the end of the message." do
116 assert_equal %Q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a>#{char}),
117 identicaify("leading #hashtag#{char}")
118 end
119
120 should "correctly parse hashtags with the character #{char} with leading and trailing words" do
121 assert_equal %Q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a>#{char} trailing),
122 identicaify("leading #hashtag#{char} trailing")
123 end
124 end
125
126 should "not turn &#39; into a link" do
127 assert_equal %q(&#39; #<a href="http://identi.ca/tag/stuff">stuff</a>),
128 identicaify("&#39; #stuff")
129 end
130
131 should "parse regression 1 correctly" do
132 assert_equal %q(Conan's #<a href="http://identi.ca/tag/Tonight_Show">Tonight_Show</a>: "In the year 3000 #<a href="http://identi.ca/tag/Facebook">Facebook</a>, #<a href="http://identi.ca/tag/Twitter">Twitter</a>, and #<a href="http://identi.ca/tag/YouTube">YouTube</a> merge to form the largest time-wasting site ever: #<a href="http://identi.ca/tag/YouTwitFace">YouTwitFace</a>."), #'
133 identicaify("Conan\'s #Tonight_Show: \"In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace.\"")
134 end
135 end
91136end