プロジェクト

全般

プロフィール

Vote #80677

完了

New line between list items break a list

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Text formatting_26
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
26
version_id:
160
issue_org_id:
32971
author_id:
443353
assigned_to_id:
332
comments:
15
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
127
ステータス-->[Closed]

説明

New line between list items break a list when I try to write ordered/unordered list with textile.

  • Example
  • list1

    • list2
    • list3

list4

# list5
# list6

  • In 3.2.1
    !3.2.1.png!

  • In 4.1.0
    !4.1.0.png!


journals

I think the behavior has probably changed by applying r17603 ( "Defect !#29756: \f or \v character in Textile markup may cause RegexpError exception":https://www.redmine.org/issues/29756 ).

https://www.redmine.org/projects/redmine/repository/revisions/17603/diff/trunk/lib/redmine/wiki_formatting/textile/redcloth3.rb

It could be resolved with the following patch.

<pre><code class="diff">
diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 80e0a3626..ff4687f7e 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1020,10 +1020,13 @@ class RedCloth3 < String
end

def flush_left( text )
- indt = 0
- if text =~ /^ /
+ if /(?![\r\n\t ])[[:cntrl:]]/.match?(text)
+ text.gsub!(/(?![\r\n\t ])[[:cntrl:]]/, '')
+ end
+ if /^ /.match?(text) && text.length > 1
+ indt = 0
unless text.empty?
- indt += 1 while text !~ /^ {#{indt}}[^ ]/
+ indt += 1 while text !~ /^ {#{indt}}\S/
end
if indt.nonzero?
text.gsub!( /^ {#{indt}}/, '' )
</code></pre>

--------------------------------------------------------------------------------
Thanks for your help Yuichi! :)

This patch works gracefully well!

Thank you again for patching it :)
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Yuichi HARADA wrote:
> I think the behavior has probably changed by applying r17603 ( "Defect !#29756: \f or \v character in Textile markup may cause RegexpError exception":https://www.redmine.org/issues/29756 ).
>
> https://www.redmine.org/projects/redmine/repository/revisions/17603/diff/trunk/lib/redmine/wiki_formatting/textile/redcloth3.rb
>
> It could be resolved with the following patch.
>
> [...]

Sorry, I found that @String#lstrip!@ could do the same.

https://www.rubydoc.info/stdlib/core/String#lstrip!-instance_method

<pre><code class="diff">
diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 80e0a3626..815f860e6 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1020,15 +1020,7 @@ class RedCloth3 < String
end

def flush_left( text )
- indt = 0
- if text =~ /^ /
- unless text.empty?
- indt += 1 while text !~ /^ {#{indt}}[^ ]/
- end
- if indt.nonzero?
- text.gsub!( /^ {#{indt}}/, '' )
- end
- end
+ text&.lstrip!
end

def footnote_ref( text )
</code></pre>
--------------------------------------------------------------------------------
Yuichi HARADA wrote:
> Yuichi HARADA wrote:
> > I think the behavior has probably changed by applying r17603 ( "Defect !#29756: \f or \v character in Textile markup may cause RegexpError exception":https://www.redmine.org/issues/29756 ).
> >
> > https://www.redmine.org/projects/redmine/repository/revisions/17603/diff/trunk/lib/redmine/wiki_formatting/textile/redcloth3.rb
> >
> > It could be resolved with the following patch.
> >
> > [...]
>
> Sorry, I found that @String#lstrip!@ could do the same.
>
> https://www.rubydoc.info/stdlib/core/String#lstrip!-instance_method
>
> [...]

It did not work well with attachment:32971-fixed-v2.patch . The same problem occurred as in the previous situation.
Please delete attachment:32971-fixed-v2.patch .
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
I fixed the attachment:32971-fixed.patch because sometimes the @flush_left@ method did not end.

<pre><code class="diff">
diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 80e0a3626..c9bdd0aeb 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1020,11 +1020,12 @@ class RedCloth3 < String
end

def flush_left( text )
- indt = 0
- if text =~ /^ /
- unless text.empty?
- indt += 1 while text !~ /^ {#{indt}}[^ ]/
- end
+ if /(?![\r\n\t ])[[:cntrl:]]/.match?(text)
+ text.gsub!(/(?![\r\n\t ])[[:cntrl:]]/, '')
+ end
+ if /^ +\S/.match?(text)
+ indt = 0
+ indt += 1 while !/^ {#{indt}}\S/.match?(text)
if indt.nonzero?
text.gsub!( /^ {#{indt}}/, '' )
end
</code></pre>
--------------------------------------------------------------------------------
How about adding a unit test to prevent future regressions of this conversion?
--------------------------------------------------------------------------------
Ji-Hyeon Gim wrote:
> New line between list items break a list when I try to write ordered/unordered list with textile.
>
> * Example
> <pre>
* list1

* list2
* list3

# list4

# list5
# list6
</pre>
>
> * In 3.2.1
> !3.2.1.png!

I noticed when looking at source:trunk/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb#L148 that this nested list is probably wrong for Textile.

<pre><code class="ruby">
def test_nested_lists
raw = <<~RAW
# Item 1
# Item 2
** Item 2a
** Item 2b
# Item 3
** Item 3a
RAW
expected = <<~EXPECTED
<ol>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2a</li>
<li>Item 2b</li>
</ul>
</li>
<li>Item 3
<ul>
<li>Item 3a</li>
</ul>
</li>
</ol>
EXPECTED
assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
end
</code></pre>

--------------------------------------------------------------------------------
Kevin Fischer wrote:
> How about adding a unit test to prevent future regressions of this conversion?

Thank you for pointing it out.
I have added the following test to attachment:32971-fixed-v3.patch .

<pre><code class="diff">
diff --git a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
index 19128524e..2358ded58 100644
--- a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
@@ -171,6 +171,24 @@ class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
</ol>
EXPECTED
assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
+
+ raw = <<~RAW
+ * Item-1
+
+ * Item-1a
+ * Item-1b
+ RAW
+ expected = <<~EXPECTED
+ <ul>
+ <li>Item-1
+ <ul>
+ <li>Item-1a</li>
+ <li>Item-1b</li>
+ </ul>
+ </li>
+ </ul>
+ EXPECTED
+ assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
end

def test_escaping
</code></pre>
--------------------------------------------------------------------------------
Tried it out. The test passed, so looks good to me!
--------------------------------------------------------------------------------
Setting the target version to 4.1.1.
--------------------------------------------------------------------------------
Committed the patch. Thank you.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,29756,\f or \v character in Textile markup may cause RegexpError exception

Admin Redmine さんが約2年前に更新

  • カテゴリText formatting_26 にセット
  • 対象バージョン4.1.1_160 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0