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

address PR comment https://github.com/opf/openproject/pull/18630#discussion_r2043791512

as-op85091980b2fc
diff --git a/app/models/work_package/pdf_export/common/attachments.rb b/app/models/work_package/pdf_export/common/attachments.rb
index 2464dfbf0ae..75a3f820461 100644
--- a/app/models/work_package/pdf_export/common/attachments.rb
+++ b/app/models/work_package/pdf_export/common/attachments.rb
@@ -71,9 +71,11 @@ module WorkPackage::PDFExport::Common::Attachments
end
def attachment_by_api_content_src(_work_package, src)
- # /attachments/#{id}/content
- parts = src.split("/")
- attachments_id = parts[-2]
+ attachment_regex = %r{/attachments/(\d+)/content}
+ return nil unless src&.match?(attachment_regex)
+
+ attachments_id = src.scan(attachment_regex).first.first
+
# return nil if the src is not an attachment url
return nil unless api_url_helpers.attachment_content(attachments_id) == src