From b9199e810af67d01e1f41d992122bec2561cbf89 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:47:23 +0100 Subject: [PATCH] Prevent user error when incorrectly formatted footnotes are added to HTML attachments When footnotes are used in HTML attachments, this function would cause an unhelpful user error to be displayed. This will allow the attachment to save. Example of incorrectly formatted footnotes: [^22]: CDC. Centre for Disease Control and Prevention. Invasive Mold Infections in Immunocompromised People [updated 06/06/2019]. Available from: Invasive Mold Infections in Immunocompromised People | Mold | CDC 23. David J. Pevalin, Aaron Reeves, Emma Baker, Rebecca Bentley, The impact of persistent poor housing conditions on mental health: A longitudinal population-based study, Preventive Medicine, Volume 105, 2017, Pages 304-310, https://doi.org/10.1016/j.ypmed.2017.09.020 22 contains the character | which triggers table formatting. 23 is not correctly formatted as a footnote. Co-authored-by: Bruce Bolt --- CHANGELOG.md | 4 ++++ lib/govspeak.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb781be7..09a39e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Prevent user error when incorrectly formatted footnotes are added to HTML attachments ([#287](https://github.com/alphagov/govspeak/pull/287)) + ## 8.2.0 * Reintroduce support for acronyms in Call To Action blocks and in Legislative Lists ([#285](https://github.com/alphagov/govspeak/pull/285)) diff --git a/lib/govspeak.rb b/lib/govspeak.rb index 4308f7ad..1b8c1fd6 100644 --- a/lib/govspeak.rb +++ b/lib/govspeak.rb @@ -451,6 +451,8 @@ def encode(text) end def add_acronym_alt_text(html) + return unless html + @acronyms.each do |acronym| html.gsub!(acronym[0], "#{acronym[0]}") end