Fix comment title encoding issue (#3311)

* Fix comment title encoding issue

* Remove puts statements

* Fix flaky test

* Change flaky test

* Add & fix
This commit is contained in:
Ben Halpern 2019-06-26 15:24:05 -04:00 committed by GitHub
parent 111e5503b4
commit 26af371ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 1 deletions

View file

@ -53,6 +53,7 @@ gem "gemoji", "~> 3.0.1" # Character information and metadata for standard and c
gem "gibbon", "~> 3.2" # API wrapper for MailChimp's API
gem "google-api-client", "~> 0.30" # Client for accessing Google APIs
gem "html_truncator", "~> 0.4" # Truncate an HTML string properly
gem 'htmlentities', '~> 4.3', '>= 4.3.4'
gem "httparty", "~> 0.16" # Makes http fun! Also, makes consuming restful web services dead easy
gem "inline_svg", "~> 1.5" # Embed SVG documents in your Rails views and style them with CSS
gem "jbuilder", "~> 2.9" # Create JSON structures via a Builder-style DSL

View file

@ -409,6 +409,7 @@ GEM
html_tokenizer (0.0.7)
html_truncator (0.4.2)
nokogiri (~> 1.5)
htmlentities (4.3.4)
http (3.3.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
@ -911,6 +912,7 @@ DEPENDENCIES
guard-livereload (~> 2.5)
guard-rspec (~> 4.7)
html_truncator (~> 0.4)
htmlentities (~> 4.3, >= 4.3.4)
httparty (~> 0.16)
inline_svg (~> 1.5)
jbuilder (~> 2.9)

View file

@ -169,7 +169,7 @@ class Comment < ApplicationRecord
return "[deleted]" if deleted
text = ActionController::Base.helpers.strip_tags(processed_html).strip
ActionController::Base.helpers.truncate(text, length: length)
HTMLEntities.new.decode ActionController::Base.helpers.truncate(text, length: length).gsub("&#39;", "'").gsub("&amp;", "&")
end
def video

View file

@ -181,6 +181,7 @@ RSpec.describe Comment, type: :model do
end
it "retains content from #processed_html" do
comment.update_column(:processed_html, "Hello this is a post.") # Remove randomness
text = comment.title.gsub("...", "").delete("\n")
expect(comment.processed_html).to include CGI.unescapeHTML(text)
end
@ -189,6 +190,12 @@ RSpec.describe Comment, type: :model do
comment.update_column(:deleted, true)
expect(comment.title).to eq "[deleted]"
end
it "does not contain the wrong encoding" do
comment.body_markdown = "It's the best post ever. It's so great."
comment.save
expect(comment.title).not_to include "&#39;"
end
end
describe "#custom_css" do