Browse Source

Sanitise name and use html safe

pull/2643/head
Manny Dinssa 2 years ago
parent
commit
c6f5f154b0
  1. 7
      app/helpers/application_helper.rb
  2. 7
      app/helpers/title_helper.rb

7
app/helpers/application_helper.rb

@ -31,6 +31,13 @@ module ApplicationHelper
!current_page?(notifications_path) && (authenticated_user_has_notifications? || unauthenticated_user_has_notifications?) !current_page?(notifications_path) && (authenticated_user_has_notifications? || unauthenticated_user_has_notifications?)
end end
def sanitise_text(text)
return if text.blank?
text.gsub(/[^a-zA-Z0-9\s\-\_\'\&]/, "")
text.html_safe
end
private private
def paginated_title(title, pagy) def paginated_title(title, pagy)

7
app/helpers/title_helper.rb

@ -4,11 +4,12 @@ module TitleHelper
end end
def format_title(searched, page_title, current_user, item_label, count, organisation_name) def format_title(searched, page_title, current_user, item_label, count, organisation_name)
sanitised_organisation_name = sanitise_text(organisation_name)
if searched.present? if searched.present?
actual_title = support_sab_nav?(current_user, organisation_name) ? organisation_name : page_title actual_title = support_sab_nav?(current_user, organisation_name) ? sanitised_organisation_name : page_title
"#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)" "#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)".html_safe
else else
support_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title support_sab_nav?(current_user, organisation_name) ? "#{sanitised_organisation_name} (#{page_title})".html_safe : page_title.html_safe
end end
end end

Loading…
Cancel
Save