Skip to content

Commit e041bce

Browse files
committed
Sanitization
1 parent 3224fbf commit e041bce

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def flash_messages(_opts = {})
119119

120120
def render_markdown(markdown_text, options = {}, renderer_options = {})
121121
if markdown_text
122-
options.reverse_merge!(filter_html: true, tables: true, autolink: true)
123-
renderer_options.reverse_merge!(hard_wrap: true, link_attributes: { target: '_blank', rel: 'noopener' })
122+
default_opts = { filter_html: true, tables: true, autolink: true }
123+
options.reverse_merge!(default_opts)
124+
renderer_options.reverse_merge!(**default_opts, hard_wrap: true, link_attributes: { target: '_blank', rel: 'noopener' })
124125
Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(renderer_options), options).render(markdown_text).html_safe
125126
else
126127
''

app/helpers/materials_helper.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,25 @@ def display_attribute(resource, attribute, show_label: true, title: nil, markdow
109109
].any?
110110

111111
value = resource.send(attribute)
112-
value = render_markdown(value) if markdown
113-
value = yield(value) if block_given? && value.present? && !list
112+
if markdown
113+
value = render_markdown(value)
114+
end
115+
if value.present?
116+
if list
117+
value = value.map do |v|
118+
html_escape(block_given? ? yield(v) : v)
119+
end
120+
else
121+
value = html_escape(block_given? ? yield(value) : value)
122+
end
123+
end
114124
string = "<p class=\"#{attribute}#{show_label ? ' no-spacing' : ''}\">"
115125
unless value.blank? || value.try(:strip) == 'License Not Specified'
116126
string << "<strong class='text-primary'> #{title || resource.class.human_attribute_name(attribute)}: </strong>" if show_label
117127
if list
118128
string << '<ul>'
119129
value.each do |v|
120-
string << "<li>#{block_given? ? yield(v) : v}</li>"
130+
string << "<li>#{v}</li>"
121131
end
122132
string << '</ul>'
123133
elsif expandable

app/views/layouts/_head.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<% if @bioschemas.present? %>
2929
<% @bioschemas.each do |data| %>
3030
<script type="application/ld+json">
31-
<%== data.to_json %>
31+
<%== json_escape(data.to_json) %>
3232
</script>
3333
<% end %>
3434
<% end %>

0 commit comments

Comments
 (0)