diff --git a/app/models/communication/website/index_page.rb b/app/models/communication/website/index_page.rb index 049d93274f930524a58782b84713c59e9185768f..6dd9431ca4276f157590fc2fd910eaf9ef3a1537 100644 --- a/app/models/communication/website/index_page.rb +++ b/app/models/communication/website/index_page.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/administrators.rb b/app/models/communication/website/index_page/administrators.rb index 77d70286367a8e15083574a31b19f0268889b6a4..d659241bfd31b36e87c64790ce33f29c0a4f1e16 100644 --- a/app/models/communication/website/index_page/administrators.rb +++ b/app/models/communication/website/index_page/administrators.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/authors.rb b/app/models/communication/website/index_page/authors.rb index ac8c199066acb3bd33ebe37d8a8fbfa0dcc20f72..e6ecbf853e8aeb6190edf7f65b5f50399069b4a3 100644 --- a/app/models/communication/website/index_page/authors.rb +++ b/app/models/communication/website/index_page/authors.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/communication_posts.rb b/app/models/communication/website/index_page/communication_posts.rb index 280f4ac363a68e2037e60d4f648777dcf48fd438..2b11622df8b163fd40e2060fbdffd35e731e7743 100644 --- a/app/models/communication/website/index_page/communication_posts.rb +++ b/app/models/communication/website/index_page/communication_posts.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/education_programs.rb b/app/models/communication/website/index_page/education_programs.rb index 6deb5218cff41a2c46aa6445d08bf1bb32f4a092..99230b5f79d6cce4dfff4e5c8e7c75d0360fd5e2 100644 --- a/app/models/communication/website/index_page/education_programs.rb +++ b/app/models/communication/website/index_page/education_programs.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/home.rb b/app/models/communication/website/index_page/home.rb index f9e5dbf862b058d08c8bb66152b0209cb0114aad..7c929c16e40ca31c022e2ddabb3652ce328cfad8 100644 --- a/app/models/communication/website/index_page/home.rb +++ b/app/models/communication/website/index_page/home.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/persons.rb b/app/models/communication/website/index_page/persons.rb index 7560b9c3bcfef26bf8db4e34c86350ebfcee3f53..d2f4063e745c3db34cff26cb04ddeeae6b421286 100644 --- a/app/models/communication/website/index_page/persons.rb +++ b/app/models/communication/website/index_page/persons.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/research_articles.rb b/app/models/communication/website/index_page/research_articles.rb index 35f8f089e8bf3905f94591a64664246ed0dcfa4c..bcf97c7c8b0c16ae53f4cffeee4690c122335a55 100644 --- a/app/models/communication/website/index_page/research_articles.rb +++ b/app/models/communication/website/index_page/research_articles.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/research_volumes.rb b/app/models/communication/website/index_page/research_volumes.rb index d21c7fd254e6955a920206c29262fb020dff5336..71c5ed187f10c0af487d32aef027566b2d0ca0bf 100644 --- a/app/models/communication/website/index_page/research_volumes.rb +++ b/app/models/communication/website/index_page/research_volumes.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/researchers.rb b/app/models/communication/website/index_page/researchers.rb index 7d0d615dbfce294fecd217670ea124992b500ffe..8fdf3b9532b4d6669b37c42ef9b275d1857deff0 100644 --- a/app/models/communication/website/index_page/researchers.rb +++ b/app/models/communication/website/index_page/researchers.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/models/communication/website/index_page/teachers.rb b/app/models/communication/website/index_page/teachers.rb index 4ce22d763ddb2268c80bd039a49e4532b617ebdd..d99383aee68768d76af15061f82ead229103aa0f 100644 --- a/app/models/communication/website/index_page/teachers.rb +++ b/app/models/communication/website/index_page/teachers.rb @@ -6,7 +6,7 @@ # breadcrumb_title :string # description :text # featured_image_alt :string -# header_text :string +# header_text :text # kind :integer # path :string # text :text diff --git a/app/services/osuny/sanitizer.rb b/app/services/osuny/sanitizer.rb index a155edb894630030dff6830a5c677932db4ca6ef..ede92d17125ac5eb9b3365f935a1a1f0c57ac37f 100644 --- a/app/services/osuny/sanitizer.rb +++ b/app/services/osuny/sanitizer.rb @@ -1,28 +1,24 @@ class Osuny::Sanitizer include ActionView::Helpers::SanitizeHelper + # type(ActiveRecord) = ['text', 'string'] def self.sanitize(input, type = 'text') return '' if input.blank? - raise ArgumentError.new('First argument must be a String') unless [String, ActionText::Content].include? input.class - - case type.to_s - when 'string' - string_sanitize(input) - when 'text' - if input.is_a? String - safe_list_sanitizer.sanitize input - else - ActionText::Content.new(safe_list_sanitizer.sanitize input.to_html) - end - else - input - end + send "sanitize_#{type}", input end private - def self.string_sanitize(raw_string) - output = Loofah.fragment(raw_string).text(encode_special_chars: false) + # input can be String or ActionText::Content + def self.sanitize_text(input) + input.is_a?(String) ? safe_list_sanitizer.sanitize(input) + : ActionText::Content.new( + safe_list_sanitizer.sanitize(input.to_html) + ) + end + + def self.sanitize_string(string) + output = Loofah.fragment(string).text(encode_special_chars: false) while output != Loofah.fragment(output).text(encode_special_chars: false) output = Loofah.fragment(output).text(encode_special_chars: false) end diff --git a/db/migrate/20220225135833_change_string_to_text_in_communication_website_index_pages.rb b/db/migrate/20220225135833_change_string_to_text_in_communication_website_index_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..0a2d7449199103882ec1d79e85feb4d261bdc488 --- /dev/null +++ b/db/migrate/20220225135833_change_string_to_text_in_communication_website_index_pages.rb @@ -0,0 +1,5 @@ +class ChangeStringToTextInCommunicationWebsiteIndexPages < ActiveRecord::Migration[6.1] + def change + change_column :communication_website_index_pages, :header_text, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 1bfa2d8e9ac3941e73ad135453296854ac07cf72..8171118765501238cbaa769e02b2bc239f41cfc9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_25_101556) do +ActiveRecord::Schema.define(version: 2022_02_25_135833) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -252,7 +252,7 @@ ActiveRecord::Schema.define(version: 2022_02_25_101556) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "breadcrumb_title" - t.string "header_text" + t.text "header_text" t.index ["communication_website_id"], name: "idx_comm_website_index_page_on_communication_website_id" t.index ["university_id"], name: "index_communication_website_index_pages_on_university_id" end