From f607e257352eba5f28811c6722ab3a6b89fa000a Mon Sep 17 00:00:00 2001 From: Mark Triggs Date: Mon, 19 Jun 2017 12:34:04 +1000 Subject: [PATCH] AR-1810 AR-1821 Treat mixed content more consistently * Don't escape strip_mixed_content. It's assumed to be OK already. * Process mixed content for titles, rather than stripping it. * Process mixed content in the PDF view and apply CSS classes to have italics show correctly. --- .../controllers/concerns/manipulate_node.rb | 20 ++++++++++++------- public-new/app/models/record.rb | 4 ++-- .../app/views/layouts/application.html.erb | 2 +- .../app/views/pdf/_archival_object.html.erb | 2 +- public-new/app/views/pdf/_header.html.erb | 8 ++++++++ public-new/app/views/pdf/_resource.html.erb | 2 +- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/public-new/app/controllers/concerns/manipulate_node.rb b/public-new/app/controllers/concerns/manipulate_node.rb index 2b7e0af7ba..305bac49d2 100644 --- a/public-new/app/controllers/concerns/manipulate_node.rb +++ b/public-new/app/controllers/concerns/manipulate_node.rb @@ -10,13 +10,11 @@ module ManipulateNode # item.name = "li" # end - def process_mixed_content(in_txt) + def process_mixed_content(in_txt, opts = {}) return if !in_txt # Don't fire up nokogiri if there's no mixed content to parse - unless in_txt.include?("<") - return CGI::escapeHTML(in_txt) - end + needs_nokogiri = in_txt.include?("<") txt = in_txt.strip @@ -24,12 +22,20 @@ def process_mixed_content(in_txt) .gsub("chronitem>", "li>") txt = txt.gsub("list>", "ul>") .gsub("item>", "li>") - .gsub(/\n\n/,"

") - .gsub(/\r\n\r\n/,"

") + + unless opts[:preserve_newlines] + txt = txt.gsub(/\n\n/,"

") + .gsub(/\r\n\r\n/,"

") + end txt = txt.gsub(/ & /, ' & ') txt = txt.gsub("xlink\:type=\"simple\"", "") + + unless needs_nokogiri + return txt + end + @frag = Nokogiri::XML.fragment(txt) move_list_heads @frag.traverse { |el| @@ -47,7 +53,7 @@ def strip_mixed_content(in_text) # Don't fire up nokogiri if there's no mixed content to parse unless in_text.include?("<") - return CGI::escapeHTML(in_text) + return in_text end in_text = in_text.gsub(/ & /, ' & ') diff --git a/public-new/app/models/record.rb b/public-new/app/models/record.rb index c50861b0b0..219d67da69 100644 --- a/public-new/app/models/record.rb +++ b/public-new/app/models/record.rb @@ -74,9 +74,9 @@ def request_item private def parse_full_title - ft = strip_mixed_content(json['display_string'] || json['title']) + ft = process_mixed_content(json['display_string'] || json['title'], :preserve_newlines => true) unless json['title_inherited'].blank? || (json['display_string'] || '') == json['title'] - ft = I18n.t('inherited', :title => strip_mixed_content(json['title']), :display => ft) + ft = I18n.t('inherited', :title => process_mixed_content(json['title'], :preserve_newlines => true), :display => ft) end ft end diff --git a/public-new/app/views/layouts/application.html.erb b/public-new/app/views/layouts/application.html.erb index ec89c145eb..754dd4293d 100644 --- a/public-new/app/views/layouts/application.html.erb +++ b/public-new/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ - <%= (@page_title.blank? ? '' : "#{@page_title} | ") %><%= t('brand.title') %> + <%= (@page_title.blank? ? '' : "#{strip_mixed_content(@page_title)} | ") %><%= t('brand.title') %> <%= csrf_meta_tags %> <%# block cross-origin refer per https://go-to-hellman.blogspot.com/2015/06/protect-reader-privacy-with-referrer.html %> <% if AppConfig[:pui_block_referrer] %> diff --git a/public-new/app/views/pdf/_archival_object.html.erb b/public-new/app/views/pdf/_archival_object.html.erb index bdfa987d14..76007a2b09 100644 --- a/public-new/app/views/pdf/_archival_object.html.erb +++ b/public-new/app/views/pdf/_archival_object.html.erb @@ -14,7 +14,7 @@ end