From 6ad2cebe83edbd08d468fbadb8252ef1fdba8b74 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 25 Oct 2021 17:57:12 +0200
Subject: [PATCH] clean title

---
 app/services/wordpress.rb                     | 10 +++++-
 .../website/imported/medium_test.rb           | 32 -------------------
 test/models/wordpress_test.rb                 |  2 +-
 3 files changed, 10 insertions(+), 34 deletions(-)
 delete mode 100644 test/models/communication/website/imported/medium_test.rb

diff --git a/app/services/wordpress.rb b/app/services/wordpress.rb
index a34aaf052..bc2f68752 100644
--- a/app/services/wordpress.rb
+++ b/app/services/wordpress.rb
@@ -1,7 +1,15 @@
 class Wordpress
   attr_reader :domain
 
-  def self.clean(html)
+
+  def self.clean_string(string)
+    string = string.gsub('&nbsp;', ' ')
+    string = string.gsub('&amp;', '&')
+    string = ActionView::Base.full_sanitizer.sanitize string
+    string
+  end
+
+  def self.clean_html(html)
     # Relaxed config : https://github.com/rgrove/sanitize/blob/main/lib/sanitize/config/relaxed.rb
     fragment = Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::RELAXED,
       attributes: Sanitize::Config::RELAXED[:attributes].merge({
diff --git a/test/models/communication/website/imported/medium_test.rb b/test/models/communication/website/imported/medium_test.rb
deleted file mode 100644
index 5add977a9..000000000
--- a/test/models/communication/website/imported/medium_test.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# == Schema Information
-#
-# Table name: communication_website_imported_media
-#
-#  id            :uuid             not null, primary key
-#  data          :jsonb
-#  file_url      :text
-#  filename      :string
-#  identifier    :string
-#  mime_type     :string
-#  created_at    :datetime
-#  updated_at    :datetime
-#  university_id :uuid             not null
-#  website_id    :uuid             not null
-#
-# Indexes
-#
-#  index_communication_website_imported_media_on_university_id  (university_id)
-#  index_communication_website_imported_media_on_website_id     (website_id)
-#
-# Foreign Keys
-#
-#  fk_rails_...  (university_id => universities.id)
-#  fk_rails_...  (website_id => communication_website_imported_websites.id)
-#
-require "test_helper"
-
-class Communication::Website::Imported::MediumTest < ActiveSupport::TestCase
-  # test "the truth" do
-  #   assert true
-  # end
-end
diff --git a/test/models/wordpress_test.rb b/test/models/wordpress_test.rb
index 23b1323b6..24a521050 100644
--- a/test/models/wordpress_test.rb
+++ b/test/models/wordpress_test.rb
@@ -57,7 +57,7 @@ class WordpressTest < ActiveSupport::TestCase
 
   test "convert &nbsp; in titles" do
     assert_equal  ' ',
-                  Wordpress.clean_string '&nbsp;'
+                  Wordpress.clean_string('&nbsp;')
   end
 
   test "authorize iframes" do
-- 
GitLab