Skip to content

Commit 563b882

Browse files
author
John Pinto
committed
Bug #3203 - Fix for download plans docx being malformed if it has
character combinations lik \0.. or \F.., e,g, as in G:\Hematologie\Onderzoek\Studie Team Hematologie\Studies op alfabet\studies\abc\00. DIGITAAL ISF\03. Contracts - Agreements\a. Clinical Trial Agreement. Fix for issue #3203. Change: The htmltoword gem converts html to docx, so we clean the html string by replacing single backslashes \ by double backslashes \\.
1 parent 036f8c7 commit 563b882

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)