Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
sanitize html
Browse files Browse the repository at this point in the history
  • Loading branch information
gdonald committed Dec 30, 2023
1 parent d671ca0 commit bda187d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require spec_helper
--order rand
--color
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gem 'rack', '~> 3.0.8'
gem 'rails', '~> 7.1.0'
gem 'rbnacl', '~> 7.1.1'
gem 'redis', '~> 5.0.7'
gem 'sanitize', '~> 6.1.0'
gem 'sassc-rails', '~> 2.1.2'
gem 'sidekiq', '~> 7.2.0'
gem 'sidekiq-cron', '~> 1.12.0'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ GEM
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sanitize (6.1.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
Expand Down Expand Up @@ -489,6 +492,7 @@ DEPENDENCIES
rubocop-rails
rubocop-rake
rubocop-rspec
sanitize (~> 6.1.0)
sassc-rails (~> 2.1.2)
selenium-webdriver
shoulda-matchers (~> 6.0.0)
Expand Down
4 changes: 2 additions & 2 deletions app/services/html_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def blurb
elem ||= doc.search(tag).first
end

elem.to_s.gsub(/<.*?>/, '').strip
Sanitize.fragment(elem.to_s).strip
end

def content
Expand All @@ -50,7 +50,7 @@ def remove_stop_words(words)
end

def remove_html_tags(text)
text.gsub(/<.*?>/, '').gsub("\n", ' ').gsub("\r", '').gsub(/\s+/, ' ').strip
Sanitize.fragment(text).gsub("\n", ' ').gsub("\r", '').gsub(/\s+/, ' ').strip
end

def find_hrefs
Expand Down

0 comments on commit bda187d

Please sign in to comment.