Changeset 7516
- Timestamp:
- 09/20/07 20:40:22 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/text_helper.rb (modified) (3 diffs)
- trunk/actionpack/test/template/text_helper_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r7514 r7516 1 1 *SVN* 2 3 * Autolink behaves well with emails embedded in URLs. #7313 [Jeremy McAnally, tarmo] 2 4 3 5 * Fixed that default layouts did not take the format into account #9564 [lifofifo] trunk/actionpack/lib/action_view/helpers/text_helper.rb
r7515 r7516 306 306 return '' if text.blank? 307 307 case link 308 when :all then auto_link_ urls(auto_link_email_addresses(text, &block), href_options, &block)308 when :all then auto_link_email_addresses(auto_link_urls(text, href_options, &block), &block) 309 309 when :email_addresses then auto_link_email_addresses(text, &block) 310 310 when :urls then auto_link_urls(text, href_options, &block) … … 535 535 (?:\.[-\w]+)* # remaining subdomains or domain 536 536 (?::\d+)? # port 537 (?:/(?:(?:[~\w\+ %-]|(?:[,.;:][^\s$]))+)?)* # path538 (?:\?[\w\+ %&=.;-]+)? # query string537 (?:/(?:(?:[~\w\+@%-]|(?:[,.;:][^\s$]))+)?)* # path 538 (?:\?[\w\+@%&=.;-]+)? # query string 539 539 (?:\#[\w\-]*)? # trailing anchor 540 540 ) … … 561 561 # each email is yielded and the result is used as the link text. 562 562 def auto_link_email_addresses(text) 563 body = text.dup 563 564 text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do 564 565 text = $1 565 text = yield(text) if block_given? 566 %{<a href="mailto:#{$1}">#{text}</a>} 566 567 if body.match(/<a\b[^>]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/) 568 text 569 else 570 display_text = (block_given?) ? yield(text) : text 571 %{<a href="mailto:#{text}">#{display_text}</a>} 572 end 567 573 end 568 574 end trunk/actionpack/test/template/text_helper_test.rb
r7515 r7516 158 158 http://www.rubyonrails.com/~minam/contact;new?with=query&string=params 159 159 http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007 160 http://www.mail-archive.com/rails@lists.rubyonrails.org/ 160 161 ) 161 162 … … 168 169 email_raw = 'david@loudthinking.com' 169 170 email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>} 171 email2_raw = '+david@loudthinking.com' 172 email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>} 170 173 link_raw = 'http://www.rubyonrails.com' 171 174 link_result = %{<a href="#{link_raw}">#{link_raw}</a>} … … 187 190 link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html' 188 191 link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>} 192 link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/' 193 link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>} 189 194 190 195 assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses) … … 226 231 assert_equal %(Go to #{link9_result}.), auto_link(%(Go to #{link9_raw}.)) 227 232 assert_equal %(<p>Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.</p>)) 233 assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>") 234 assert_equal email2_result, auto_link(email2_raw) 228 235 assert_equal '', auto_link(nil) 229 236 assert_equal '', auto_link('')