From f5768f9252ee04adfa06bdc7d9b6f56370892970 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Wed, 10 Jul 2024 09:33:48 +0000 Subject: [PATCH] Merged r22905, r22906, and r22907 from trunk to 5.1-stable (#40716). git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@22918 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 1 - lib/redmine/wiki_formatting/section_helper.rb | 6 +++--- .../wiki_formatting/common_mark/formatter_test.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1c7208e3f..75920e2c4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1450,7 +1450,6 @@ Style/RedundantRegexpEscape: - 'lib/redmine/scm/adapters/bazaar_adapter.rb' - 'lib/redmine/wiki_formatting/links_helper.rb' - 'lib/redmine/wiki_formatting/macros.rb' - - 'lib/redmine/wiki_formatting/section_helper.rb' - 'lib/redmine/wiki_formatting/textile/redcloth3.rb' - 'test/helpers/application_helper_test.rb' diff --git a/lib/redmine/wiki_formatting/section_helper.rb b/lib/redmine/wiki_formatting/section_helper.rb index 9221d990d..7d0b974de 100644 --- a/lib/redmine/wiki_formatting/section_helper.rb +++ b/lib/redmine/wiki_formatting/section_helper.rb @@ -42,7 +42,7 @@ module Redmine i = 0 l = 1 inside_pre = false - @text.split(/(^(?:\S+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part| + @text.split(/(^(?:\S+\r?\n\r?(?:=+|-+)|#+ .+|(?:~~~|```).*)\s*$)/).each do |part| level = nil if part =~ /\A(~{3,}|`{3,})(\s*\S+)?\s*$/ if !inside_pre @@ -52,9 +52,9 @@ module Redmine end elsif inside_pre # nop - elsif part =~ /\A(#+).+/ + elsif part =~ /\A(#+) .+/ level = $1.size - elsif part =~ /\A.+\r?\n\r?(\=+|\-+)\s*$/ + elsif part =~ /\A.+\r?\n\r?(=+|-+)\s*$/ level = $1.include?('=') ? 1 : 2 end if level diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb index 16bd8c972..b9e12ba51 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb @@ -207,6 +207,21 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase assert_section_with_hash STR_WITH_PRE[2], text, 3 end + def test_get_section_should_not_recognize_double_hash_issue_reference_as_heading + text = <<~STR + ## Section A + + This text is a part of Section A. + + ##1 : This is an issue reference, not an ATX heading. + + This text is also a part of Section A. + + STR + + assert_section_with_hash text.chomp, text, 1 + end + def test_update_section_should_not_escape_pre_content_outside_section text = STR_WITH_PRE.join("\n\n") replacement = "New text" -- 2.39.5