Permalink
Browse files

Clean up message body output

  • Loading branch information...
1 parent cc88cdd commit ce8cf98846affe724c5071ae3412fc9c6ab9b7d0 @laserlemon laserlemon committed Aug 4, 2011
Showing with 14 additions and 2 deletions.
  1. +13 −1 app/helpers/application_helper.rb
  2. +1 −1 app/views/messages/_message.html.erb
@@ -5,7 +5,19 @@ def avatar(user)
image_tag user.avatar_url, :class => "avatar", :alt => user.name, :title => user.name
end
+ def clean_body(body)
+ simple_format auto_link(once_escaped(body)){|l| short_link(l) }
+ end
+
+ def once_escaped(text)
+ begin
+ old_text = text
+ text = CGI.unescape_html(old_text)
+ end until text == old_text
+ h(text)
+ end
+
def short_link(link)
- truncate link.sub(/^https?:\/\//i, ""), :omission => ""
+ truncate link.sub(/^https?:\/\//i, "").sub(/\/$/, ""), :omission => ""
end
end
@@ -1,3 +1,3 @@
<% cache message do %>
-<li><%= avatar message.user %><%= simple_format auto_link(message.body){|l| short_link(l) } %></li>
+<li><%= avatar message.user %><%= clean_body message.body %></li>
<% end %>

0 comments on commit ce8cf98

Please sign in to comment.