Skip to content

Commit

Permalink
Use sanitize helper instead of #html_safe
Browse files Browse the repository at this point in the history
Marking unknown strings as `#html_safe` in a view is not safe. This fixes many
instances of this, in favor of using the `sanitize` helper.

Related to #3187; #3229.
  • Loading branch information
Tom Johnson committed Aug 31, 2018
1 parent 4759fa5 commit 29e1fef
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/views/hyrax/batch_edits/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="scrollx scrolly fileHeight"> <!-- original values -->
<h3> <b>Changes will be applied to: (<%= @form.names.size %> works) </b></h3>
<%= @form.names.join(", ").html_safe %>
<%= sanitize @form.names.join(", ") %>
</div> <!-- /original values -->

<div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/dashboard/collections/_flash_msg.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% if flash[type].present? %>
<div class="alert <%= flash_dom_class %> alert-dismissable" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<%= safe_join(Array.wrap(flash[type]).map(&:html_safe), '<br/>'.html_safe) %>
<%= sanitize safe_join(Array.wrap(flash[type]), tag(:br)) %>
</div>
<% flash.delete(type) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/file_sets/_extra_fields_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<h2 id="extraFieldsModal_<%= name %>_Label">Additional <%= label %>(s)</h2>
</div>
<div class="modal-body">
<%= values.join("<br />").html_safe %>
<%= sanitize values.join("<br />") %>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal">Close</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% @presenter.characterization_metadata.keys.each do |term| %>
<div>
<% additional_values = @presenter.secondary_characterization_values(term) %>
<%= @presenter.label_for_term(term) %>: <%= @presenter.primary_characterization_values(term).join("<br />").html_safe %>
<%= @presenter.label_for_term(term) %>: <%= sanitize @presenter.primary_characterization_values(term).join("<br />") %>
<% unless additional_values.empty? %>
<%= render partial: "extra_fields_modal", locals: { name: term, values: additional_values } %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/notifications/_notifications.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<%= msg.last_message.created_at.to_formatted_s(:long_ordinal) %>
</relative-time>
</td>
<td><%= msg.last_message.subject.html_safe %></td>
<td><%= msg.last_message.body.html_safe %></td>
<td><%= sanitize msg.last_message.subject %></td>
<td><%= sanitize msg.last_message.body %></td>
<td>
<%= link_to hyrax.notification_path(msg.id),
class: "itemicon itemtrash",
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/stats/file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script>
//<![CDATA[

var hyrax_item_stats = <%= @stats.to_flot.to_json.html_safe %>;
var hyrax_item_stats = <%= sanitize @stats.to_flot.to_json %>;

//]]>
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/stats/work.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script>
//<![CDATA[

var hyrax_item_stats = <%= @stats.to_flot.to_json.html_safe %>;
var hyrax_item_stats = <%= sanitize @stats.to_flot.to_json %>;

//]]>
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/users/_activity_log.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% events.each do |event| %>
<% next if event[:action].blank? or event[:timestamp].blank? %>
<tr>
<td><%= event[:action].html_safe %></td>
<td><%= sanitize event[:action] %></td>
<% time = Time.zone.at(event[:timestamp].to_i) %>
<td data-sort="<%= time.getutc.iso8601(5) %>">
<relative-time datetime="<%= time.getutc.iso8601 %>" title="<%= time.to_formatted_s(:standard) %>">
Expand Down

0 comments on commit 29e1fef

Please sign in to comment.