diff --git a/benchmarks/lobsters/app/models/story.rb b/benchmarks/lobsters/app/models/story.rb index 13d18867..29cb7676 100644 --- a/benchmarks/lobsters/app/models/story.rb +++ b/benchmarks/lobsters/app/models/story.rb @@ -503,7 +503,7 @@ def description_or_story_text(chars = 0) s = s.to_s[0, chars].gsub(/ [^ ]*\z/, "") end - HTMLEntities.new.decode(s.to_s) + HtmlEncoder.encode(s.to_s) end def domain_search_url diff --git a/benchmarks/lobsters/app/views/comments/index.rss.erb b/benchmarks/lobsters/app/views/comments/index.rss.erb index 6809f60d..b7b61ddf 100644 --- a/benchmarks/lobsters/app/views/comments/index.rss.erb +++ b/benchmarks/lobsters/app/views/comments/index.rss.erb @@ -1,5 +1,4 @@ -<% coder = HTMLEntities.new %> <%= Rails.application.name %><%= @title.present? ? @@ -9,14 +8,13 @@ <% @comments.each do |comment| %> <item> - <title>on <%= raw coder.encode(comment.story.title, :decimal) %> + on <%= raw HtmlEncoder.encode(comment.story.title) %> <%= comment.url %> <%= comment.short_id_url %> <%= comment.user.username %>@users.<%= Rails.application.domain %> (<%= comment.user.username %>) <%= comment.created_at.rfc2822 %> <%= comment.url %> - <%= raw coder.encode(comment.markeddown_comment, - :decimal) %> + <%= raw HtmlEncoder.encode(comment.markeddown_comment) %> <% end %> diff --git a/benchmarks/lobsters/app/views/home/rss.erb b/benchmarks/lobsters/app/views/home/rss.erb index 753a9a2c..5aa42bfc 100644 --- a/benchmarks/lobsters/app/views/home/rss.erb +++ b/benchmarks/lobsters/app/views/home/rss.erb @@ -1,5 +1,4 @@ -<% coder = HTMLEntities.new %> <%= Rails.application.name %><%= @title.present? ? @@ -10,17 +9,17 @@ <% @stories.each do |story| %> <item> - <title><%= raw coder.encode(story.title, :decimal) %> + <%= raw HtmlEncoder.encode(story.title) %> <%= story.url_or_comments_url %> <%= story.short_id_url %> <%= story.user.username %>@users.<%= Rails.application.domain %> (<%= story.user.username %>) <%= story.created_at.rfc2822 %> <%= story.comments_url %> - <%= raw coder.encode(story.markeddown_description, :decimal) %> + <%= raw HtmlEncoder.encode(story.markeddown_description) %> <% if story.url.present? %> - <%= raw coder.encode("

" + - link_to("Comments", story.comments_url) + "

", :decimal) %> + <%= raw HtmlEncoder.encode("

" + + link_to("Comments", story.comments_url) + "

") %> <% end %>
<% story.taggings.each do |tagging| %> diff --git a/benchmarks/lobsters/extras/html_encoder.rb b/benchmarks/lobsters/extras/html_encoder.rb new file mode 100644 index 00000000..94e07bb4 --- /dev/null +++ b/benchmarks/lobsters/extras/html_encoder.rb @@ -0,0 +1,17 @@ +# typed: false + +require "cgi" + +module HtmlEncoder + HTML_ENTITIES = HTMLEntities.new + + class << self + def encode(string, type = :decimal) + HTML_ENTITIES.encode(string, type) + end + + def decode(encoded_string) + CGI.unescape_html(encoded_string) + end + end +end