Skip to content

Commit 5e763a3

Browse files
committed
Only pass in safe HTML to govspeak component
This makes sure that we only pass in safe HTML to the govspeak component, because in the future the component won't call `html_safe` on it for us (alphagov/govuk_publishing_components#356). In some cases I've used `raw` because the input may be nil.
1 parent 16a0247 commit 5e763a3

24 files changed

+30
-28
lines changed

app/presenters/content_item/body.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def body
66

77
def govspeak_body
88
{
9-
content: body,
9+
content: body.html_safe,
1010
direction: text_direction
1111
}
1212
end

app/views/content_items/_body_with_related_links.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="grid-row responsive-bottom-margin">
1111
<div class="column-two-thirds">
1212
<%= render 'govuk_publishing_components/components/govspeak',
13-
content: @content_item.body,
13+
content: raw(@content_item.body),
1414
direction: page_text_direction,
1515
disable_youtube_expansions: true,
1616
rich_govspeak: true %>

app/views/content_items/_document_collection_body.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<%= @content_item.group_heading(group) %>
77
<% if group["body"].present? %>
88
<%= render 'govuk_publishing_components/components/govspeak',
9-
content: group["body"],
9+
content: raw(group["body"]),
1010
direction: page_text_direction %>
1111
<% end %>
1212

app/views/content_items/_publication_inline_body.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div aria-labelledby="documents-title">
77
<%= render 'govuk_publishing_components/components/govspeak',
8-
content: @content_item.documents,
8+
content: @content_item.documents.html_safe,
99
direction: page_text_direction %>
1010
</div>
1111

@@ -16,6 +16,6 @@
1616

1717
<div aria-labelledby="details-title">
1818
<%= render 'govuk_publishing_components/components/govspeak',
19-
content: @content_item.details,
19+
content: @content_item.details.html_safe,
2020
direction: page_text_direction %>
2121
</div>

app/views/content_items/case_study.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
caption: @content_item.image["caption"] if @content_item.image %>
2727

2828
<%= render 'govuk_publishing_components/components/govspeak',
29-
content: @content_item.body,
29+
content: @content_item.body.html_safe,
3030
direction: page_text_direction %>
3131
</div>
3232

app/views/content_items/consultation.html.erb

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
<%= render 'govuk_publishing_components/components/heading', text: "Download the full outcome", mobile_top_margin: true %>
4141
<div class="consultation-outcome">
4242
<%= render 'govuk_publishing_components/components/govspeak',
43-
content: @content_item.final_outcome_documents,
43+
content: @content_item.final_outcome_documents.html_safe,
4444
direction: page_text_direction %>
4545
</div>
4646
<% end %>
4747

4848
<%= render 'govuk_publishing_components/components/heading', text: "Detail of outcome", mobile_top_margin: true %>
4949
<div class="consultation-outcome-detail">
5050
<%= render 'govuk_publishing_components/components/govspeak',
51-
content: @content_item.final_outcome_detail,
51+
content: @content_item.final_outcome_detail.html_safe,
5252
direction: page_text_direction %>
5353
</div>
5454
<% end %>
@@ -57,7 +57,7 @@
5757
<%= render 'govuk_publishing_components/components/heading', text: "Feedback received", mobile_top_margin: true %>
5858
<div class="consultation-feedback-documents">
5959
<%= render 'govuk_publishing_components/components/govspeak',
60-
content: @content_item.public_feedback_documents,
60+
content: @content_item.public_feedback_documents.html_safe,
6161
direction: page_text_direction %>
6262
</div >
6363
<% end %>
@@ -66,7 +66,7 @@
6666
<%= render 'govuk_publishing_components/components/heading', text: "Detail of feedback received", mobile_top_margin: true %>
6767
<div class="consultation-feedback">
6868
<%= render 'govuk_publishing_components/components/govspeak',
69-
content: @content_item.public_feedback_detail,
69+
content: @content_item.public_feedback_detail.html_safe,
7070
direction: page_text_direction %>
7171
</div>
7272
<% end %>
@@ -115,7 +115,7 @@
115115
<%= render 'govuk_publishing_components/components/heading', text: "Documents", mobile_top_margin: true %>
116116
<div class="consultation-documents">
117117
<%= render 'govuk_publishing_components/components/govspeak',
118-
content: @content_item.documents,
118+
content: @content_item.documents.html_safe,
119119
direction: page_text_direction %>
120120
</div>
121121
<% end %>

app/views/content_items/corporate_information_page.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<div class="column-two-thirds">
4848
<%= render "components/contents-list-with-body", contents: @content_item.contents do %>
4949
<div class="responsive-bottom-margin">
50-
<%= render 'govuk_publishing_components/components/govspeak', content: "#{@content_item.body}#{@additional_body}" %>
50+
<%= render 'govuk_publishing_components/components/govspeak', content: "#{@content_item.body}#{@additional_body}".html_safe %>
5151
</div>
5252
<% end %>
5353
</div>

app/views/content_items/fatality_notice.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
alt: @content_item.image["alt_text"],
2828
caption: @content_item.image["caption"] if @content_item.image %>
2929
<%= render 'govuk_publishing_components/components/govspeak',
30-
content: @content_item.body,
30+
content: @content_item.body.html_safe,
3131
direction: page_text_direction %>
3232
</div>
3333

app/views/content_items/gone.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
The information on this page has been removed because it was published in error.
77
</p>
88

9-
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.explanation %>
9+
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.explanation.html_safe %>
1010

1111
<% if @content_item.alternative_path.present? %>
1212
<p class="alternative">

app/views/content_items/guide.html+print.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<%= "#{index + 1}. #{part['title']}" %>
1616
</h1>
1717
<%= render 'govuk_publishing_components/components/govspeak',
18-
content: part['body'],
18+
content: part['body'].html_safe,
1919
direction: page_text_direction,
2020
disable_youtube_expansions: true,
2121
rich_govspeak: true %>

app/views/content_items/guide.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</h1>
2525
<% end %>
2626
<%= render 'govuk_publishing_components/components/govspeak',
27-
content: @content_item.current_part_body,
27+
content: @content_item.current_part_body.html_safe,
2828
direction: page_text_direction,
2929
disable_youtube_expansions: true,
3030
rich_govspeak: true %>

app/views/content_items/news_article.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
alt: @content_item.image["alt_text"],
2727
caption: @content_item.image["caption"] if @content_item.image %>
2828
<%= render 'govuk_publishing_components/components/govspeak',
29-
content: @content_item.body,
29+
content: @content_item.body.html_safe,
3030
direction: page_text_direction %>
3131
</div>
3232

app/views/content_items/service_sign_in/_choose_sign_in.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<%= render "govuk_publishing_components/components/fieldset", legend_text: legend_text do %>
2222
<div class="grid-row">
2323
<div class="column-two-thirds">
24-
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.description %>
24+
<%= render 'govuk_publishing_components/components/govspeak', content: raw(@content_item.description) %>
2525
<% if @error %>
2626
<%= render "components/error-message", text: t('service_sign_in.error.option') %>
2727
<% end %>

app/views/content_items/service_sign_in/_create_new_account.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<div class="grid-row">
44
<div class="column-two-thirds">
55
<%= render 'govuk_publishing_components/components/title', title: @content_item.title %>
6-
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.body %>
6+
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.body.html_safe %>
77
</div>
88
</div>

app/views/content_items/speech.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
caption: @content_item.image["caption"] if @content_item.image %>
3131

3232
<%= render 'govuk_publishing_components/components/govspeak',
33-
content: @content_item.body,
33+
content: @content_item.body.html_safe,
3434
direction: page_text_direction %>
3535
</div>
3636

app/views/content_items/statistical_data_set.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<%= render "components/contents-list-with-body", contents: @content_item.contents do %>
2828
<div class="responsive-bottom-margin">
2929
<%= render 'govuk_publishing_components/components/govspeak',
30-
content: @content_item.body,
30+
content: @content_item.body.html_safe,
3131
direction: page_text_direction %>
3232
</div>
3333
<div class="responsive-bottom-margin">

app/views/content_items/take_part.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
caption: @content_item.image["caption"] if @content_item.image %>
2222

2323
<%= render 'govuk_publishing_components/components/govspeak',
24-
content: @content_item.body,
24+
content: @content_item.body.html_safe,
2525
direction: page_text_direction %>
2626
</div>
2727
<%= render 'shared/sidebar_navigation' %>

app/views/content_items/topical_event_about_page.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
contents: @content_item.contents,
1919
} do %>
2020
<%= render 'govuk_publishing_components/components/govspeak',
21-
content: @content_item.body,
21+
content: @content_item.body.html_safe,
2222
direction: page_text_direction %>
2323
<% end %>
2424
</div>

app/views/content_items/travel_advice.html+print.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<%= render 'shared/travel_advice_summary', content_item: @content_item if i == 0 %>
1919

2020
<%= render 'govuk_publishing_components/components/govspeak',
21-
content: part['body'],
21+
content: part['body'].html_safe,
2222
direction: page_text_direction %>
2323
</section>
2424
<% end %>

app/views/content_items/travel_advice.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<% end %>
5252

5353
<%= render 'govuk_publishing_components/components/govspeak',
54-
content: @content_item.current_part_body,
54+
content: @content_item.current_part_body.html_safe,
5555
direction: page_text_direction %>
5656

5757
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>

app/views/content_items/unpublishing.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
The information on this page has been removed because it was published in error.
77
</p>
88

9-
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.explanation %>
9+
<%= render 'govuk_publishing_components/components/govspeak', content: @content_item.explanation.html_safe %>
1010

1111
<% if @content_item.alternative_url.present? %>
1212
<p class="alternative">

app/views/content_items/working_group.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %>
3030
<%= render 'components/contents-list-with-body', contents: @content_item.contents do %>
3131
<%= render 'govuk_publishing_components/components/govspeak',
32-
content: "#{@content_item.body} #{@additional_body}",
32+
content: "#{@content_item.body} #{@additional_body}".html_safe,
3333
direction: page_text_direction %>
3434
<% end %>
3535
</div>

app/views/content_items/world_location_news_article.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
caption: @content_item.image["caption"] if @content_item.image %>
2828

2929
<%= render 'govuk_publishing_components/components/govspeak',
30-
content: @content_item.body,
30+
content: @content_item.body.html_safe,
3131
direction: page_text_direction %>
3232
</div>
3333

test/test_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ def setup_and_visit_random_content_item(document_type: nil)
178178
stub_request(:get, %r{#{path}})
179179
.to_return(status: 200, body: content_item.to_json, headers: {})
180180
visit path
181+
182+
assert_equal 200, page.status_code
181183
end
182184

183185
def get_content_example(name)

0 commit comments

Comments
 (0)