The phpBB import script successfully recognizes and imports the attachments to Discourse but fails to embed them correctly in the posts’ Markdown.
The issue is in
TextProcessor::process_attachments which is responsible for embedding the attachment Markdown code to the post text.
# This replaces existing [attachment] BBCodes with the corresponding HTML tags for Discourse. # All attachments that haven't been referenced in the text are appended to the end of the text. def process_attachments(text, attachments) attachment_regexp = /\[attachment=([\d])+\]<!-- [\w]+ -->([^<]+)<!-- [\w]+ -->\[\/attachment\]?/i unreferenced_attachments = attachments.dup text = text.gsub(attachment_regexp) do index = $1.to_i real_filename = $2 unreferenced_attachments[index] = nil attachments.fetch(index, real_filename) end add_unreferenced_attachments(text, unreferenced_attachments) end
The faulty line is
text = text.gsub(attachment_regexp) do since it causes the
text reference to change only inside
process_attachments (see How arguments are passed? in Ruby docs) and the return value even though it is correct, is not used by the caller.
text = text.gsub(...) is changed to
I wasn’t sure where to add tests. Any suggestions would be welcome.