diff --git a/Gemfile b/Gemfile index ba96e37c5..b3d0d0546 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,6 @@ gem "hairtrigger", "~> 0.2.24" # HairTrigger lets you create and manage database gem "honeybadger", "~> 4.9" # Used for tracking application errors gem "honeycomb-beeline", "~> 2.8.0" # Monitoring and Observability gem gem "html_truncator", "~> 0.4" # Truncate an HTML string properly -gem "htmlentities", "~> 4.3", ">= 4.3.4" # A module for encoding and decoding (X)HTML entities gem "httparty", "~> 0.20" # Makes http fun! Also, makes consuming restful web services dead easy gem "httpclient", "~> 2.8.3" # Gives something like the functionality of libwww-perl (LWP) in Ruby gem "i18n-js", "~> 3.9.0" # Helps with internationalization in Rails. diff --git a/Gemfile.lock b/Gemfile.lock index edd9f8155..29fd057dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -360,7 +360,6 @@ GEM html_tokenizer (0.0.7) html_truncator (0.4.2) nokogiri (~> 1.5) - htmlentities (4.3.4) http-2 (0.11.0) http (4.4.1) addressable (~> 2.3) @@ -942,7 +941,6 @@ DEPENDENCIES honeybadger (~> 4.9) honeycomb-beeline (~> 2.8.0) html_truncator (~> 0.4) - htmlentities (~> 4.3, >= 4.3.4) httparty (~> 0.20) httpclient (~> 2.8.3) hypershield (~> 0.2.2) diff --git a/app/models/comment.rb b/app/models/comment.rb index 542999443..6b9e46418 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -57,7 +57,6 @@ class Comment < ApplicationRecord validates :positive_reactions_count, presence: true validates :public_reactions_count, presence: true validates :reactions_count, presence: true - validates :user_id, presence: true validates :commentable, on: :create, presence: { message: lambda do |object, _data| "#{object.commentable_type.presence || 'item'} has been deleted." @@ -140,7 +139,7 @@ class Comment < ApplicationRecord text = ActionController::Base.helpers.strip_tags(processed_html).strip truncated_text = ActionController::Base.helpers.truncate(text, length: length).gsub("'", "'").gsub("&", "&") - HTMLEntities.new.decode(truncated_text) + Nokogiri::HTML.fragment(truncated_text).text # unescapes all HTML entities end def video diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index af0424c47..49b6264ef 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -22,7 +22,6 @@ RSpec.describe Comment, type: :model do it { is_expected.to validate_presence_of(:positive_reactions_count) } it { is_expected.to validate_presence_of(:public_reactions_count) } it { is_expected.to validate_presence_of(:reactions_count) } - it { is_expected.to validate_presence_of(:user_id) } end it do @@ -329,6 +328,14 @@ RSpec.describe Comment, type: :model do comment.validate! expect(comment.title).not_to include("'") end + + # NOTE: example string taken from https://github.com/threedaymonk/htmlentities + # as this is the gem we're removing. + it "correctly decodes HTML entities" do + comment.body_markdown = "élan" + comment.validate! + expect(comment.title).to eq("élan") + end end describe "#custom_css" do diff --git a/vendor/cache/htmlentities-4.3.4.gem b/vendor/cache/htmlentities-4.3.4.gem deleted file mode 100644 index fdb45623a..000000000 Binary files a/vendor/cache/htmlentities-4.3.4.gem and /dev/null differ