From 6212fdc5415f72d849b1e0916a1c148edfccb722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Wed, 17 Jun 2026 00:48:15 +0300 Subject: [PATCH] Fix section edit links inside and after the collapse macro (#44164) --- app/helpers/application_helper.rb | 2 +- test/helpers/application_helper_test.rb | 54 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 35b895892..1bc94c235 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -971,12 +971,12 @@ module ApplicationHelper @heading_anchors = {} @current_section = 0 if options[:edit_section_links] - parse_sections(text, project, obj, attr, only_path, options) text = parse_non_pre_blocks(text, obj, macros, options) do |txt| [:parse_wiki_links, :parse_redmine_links].each do |method_name| send method_name, txt, project, obj, attr, only_path, options end end + parse_sections(text, project, obj, attr, only_path, options) parse_headings(text, project, obj, attr, only_path, options) if @parsed_headings.any? diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index ef0488c8c..0f9a81ef3 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1624,6 +1624,60 @@ class ApplicationHelperTest < Redmine::HelperTest end end + def test_section_edit_links_with_collapse_macro + raw = <<~RAW + # Wiki + ## Section A + + collapsed section + {{collapse(View details...) + ## Section B + }} + + ## Section C + RAW + @project = Project.find(1) + set_language_if_valid 'en' + with_settings :text_formatting => 'common_mark' do + result = + textilizable( + raw, + :edit_section_links => + {:controller => 'wiki', :action => 'edit', + :project_id => '1', :id => 'Test'} + ).delete("\n") + + # Section B inside collapse macro should have section=3 edit link + assert_match( + Regexp.new( + '
' \ + '' \ + '' \ + 'Edit this section' \ + '
' \ + '' \ + '

Section B

' + ), + result + ) + + # Section C after collapse macro should have section=4 edit link + assert_match( + Regexp.new( + '
' \ + '' \ + '' \ + 'Edit this section' \ + '
' \ + '' \ + '

Section C

' + ), + result + ) + end + end + + def test_default_formatter with_settings :text_formatting => 'unknown' do text = 'a *link*: http://www.example.net/' -- 2.50.1 (Apple Git-155)