Skip to content

Commit 08853aa

Browse files
authored
Merge pull request #3207 from DMPRoadmap/bug_3203_error_in_docx_xml_when-dowloading_plans
Bug #3203 - Fix for download plans docx being malformed if it has
2 parents 9a71eb2 + 563b882 commit 08853aa

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

app/controllers/plan_exports_controller.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def show_text
7878
def show_docx
7979
# Using and optional locals_assign export_format
8080
render docx: "#{file_name}.docx",
81-
content: render_to_string(partial: 'shared/export/plan',
82-
locals: { export_format: 'docx' })
81+
content: clean_html_for_docx_creation(render_to_string(partial: 'shared/export/plan',
82+
locals: { export_format: 'docx' }))
8383
end
8484

8585
def show_pdf
@@ -136,4 +136,11 @@ def export_params
136136
:custom_sections, :research_outputs,
137137
formatting: [:font_face, :font_size, { margin: %i[top right bottom left] }])
138138
end
139+
140+
# A method to deal with problematic text combinations
141+
# in html that break docx creation by htmltoword gem.
142+
def clean_html_for_docx_creation(html)
143+
# Replaces single backslash \ with \\ with gsub.
144+
html.gsub(/\\/, '\&\&')
145+
end
139146
end

0 commit comments

Comments
 (0)