Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#65709] PDF export fails if linked wp ID contains invalid letters

as-opcbc43889d43e
diff --git a/app/models/work_package/pdf_export/export/markdown.rb b/app/models/work_package/pdf_export/export/markdown.rb
index da5d05213a4..11d4cdfef16 100644
--- a/app/models/work_package/pdf_export/export/markdown.rb
+++ b/app/models/work_package/pdf_export/export/markdown.rb
@@ -94,22 +94,27 @@ module WorkPackage::PDFExport::Export::Markdown
# clear the text content, so it does not get rendered
next_node.string_content = ""
end
- wp_mention_macro(tag.attr("data-text") || "", id, opts)
+ wp_mention_macro(tag.attr("data-text") || "", id.delete("#"), opts)
end
- def wp_mention_macro(content, id, opts)
+ def expand_wp_mention(work_package, content)
count = content.count("#")
if count > 1
- work_package = WorkPackage.find_by(id: id)
- unless work_package.nil? || !work_package.visible?
- # ##1234: {Type} #{ID}: {Subject}
- content = "#{work_package.type} ##{work_package.id}: #{work_package.subject}"
- if count == 3
- # ###1234: {Status} {Type} #{ID}: {Subject} ({Start Date} - {End Date})
- content = "#{work_package.status.name} #{content}#{work_package_dates(work_package)}"
- end
+ # ##1234: {Type} #{ID}: {Subject}
+ content = "#{work_package.type} ##{work_package.id}: #{work_package.subject}"
+ if count == 3
+ # ###1234: {Status} {Type} #{ID}: {Subject} ({Start Date} - {End Date})
+ content = "#{work_package.status.name} #{content}#{work_package_dates(work_package)}"
end
end
+ content
+ end
+
+ def wp_mention_macro(content, id, opts)
+ work_package = WorkPackage.find_by(id: id)
+ return [text_hash(content, opts)] if work_package.nil? || !work_package.visible?
+
+ content = expand_wp_mention(work_package, content)
[text_hash(content, opts.merge({ link: url_helpers.work_package_url(id) }))]
end