Skip to content

Commit

Permalink
Merge pull request #3672 from sul-dlss/t3671-collection-summary
Browse files Browse the repository at this point in the history
Encode html &#13 as \r for display
  • Loading branch information
corylown authored Nov 28, 2023
2 parents 96a11fc + 712aa8f commit f518129
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ def linked_mods_genres(genres)
end
end.join('').html_safe
end

##
# Expose format_mods_html from mods_display to properly encode content as needed
# RecordHelper behavior
def format_record_html(...)
format_mods_html(...)
end
end
2 changes: 1 addition & 1 deletion app/views/catalog/mastheads/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% if @parent[:summary_display] %>
<div class="collection-summary">
<div data-behavior='truncate'>
<%= @parent[:summary_display].join(', ') %>
<%= format_record_html(@parent[:summary_display].join(', ')) %>
</div>
</div>
<% end %>
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/record_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@
end
end
end

describe 'record html' do
context 'when the record has line feeds in the string' do
let(:html) { "some text\r\nsome other text" }

it 'returns the string without changing the encoding' do
expect(helper.format_record_html(html)).to eq "some text\r\nsome other text"
end
end

context 'when the record has encoded line feeds in the string' do
let(:html) { "some text&#13\nsome other text" }

it 'returns the string with proper encoding' do
expect(helper.format_record_html(html)).to eq "some text\r\nsome other text"
end
end
end
end

0 comments on commit f518129

Please sign in to comment.