Defect #8395

Tags start with 'pre' are handled as 'pre' tag in Textile

Added by Joe Kandaba over 7 years ago. Updated 14 days ago.

Status:ClosedStart date:2011-05-18
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Text formatting
Target version:3.4.7
Resolution:Fixed Affected version:1.1.3

Description

If you use < and > in your wiki you might have something like:

<previous> <next> etc...

As you can see above the < previous > is handled as < pre > which i think should not be the case and is a bug in the parser.

pre-parse-bug@2x.png (6.05 KB) Go MAEDA, 2018-10-06 01:48

8395-note4.png (7.79 KB) Go MAEDA, 2018-11-19 01:04

8395-note4.png (7.79 KB) Go MAEDA, 2018-11-19 01:06

test_for_8395.patch Magnifier (818 Bytes) Marius BALTEANU, 2018-11-26 00:42


Related issues

Related to Redmine - Defect #7375: <pre> ... </pre> doesn't escape wiki syntax correctly Closed 2011-01-19
Duplicated by Redmine - Defect #7309: '<pre/>' tag Closed 2011-01-12

Associated revisions

Revision 17636
Added by Go MAEDA 14 days ago

Tags start with 'pre' are handled as 'pre' tag in Textile (#8395).

Patch by Takenori TAKAKI and Marius BALTEANU.

Revision 17637
Added by Go MAEDA 14 days ago

Merged r17636 from trunk to 3.4-stable (#8395).

History

#1 Updated by Etienne Massip over 7 years ago

  • Category changed from Wiki to Text formatting
  • Target version set to Candidate for next minor release

#2 Updated by Go MAEDA 2 months ago

  • File pre-parse-bug@2x.png added
  • Subject changed from Parsing of pre tag in wiki is buggy to Tags start with 'pre' are handled as 'pre' tag in Textile
  • Description updated (diff)

This old bug is still alive in Redmine 4.0 under development.

"preeeee" in the following text is misrecognized as "pre".

<preeeee>
aaaaaaa
</preeeee>

#3 Updated by Go MAEDA 2 months ago

  • Description updated (diff)

#4 Updated by Takenori TAKAKI 25 days ago

To fix this probrem, It would be necessary to add a harf-space character
between the pattern of tag name and pattern of the attributes in the regxp defined on RedCloth3::OFFTAG_MATCH.

As below.

diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 6ffd7c78c..074017a35 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1049,7 +1049,7 @@ class RedCloth3 < String
     end

     OFFTAGS = /(code|pre|kbd|notextile)/
-    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\W|\Z)/mi
+    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS } [^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\W|\Z)/mi
     OFFTAG_OPEN = /<#{ OFFTAGS }/
     OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
     HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m

#5 Updated by Go MAEDA 21 days ago

Takenori TAKAKI wrote:

To fix this probrem, It would be necessary to add a harf-space character
between the pattern of tag name and pattern of the attributes in the regxp defined on RedCloth3::OFFTAG_MATCH.

As below.
[...]

After applying the patch #8395#note-4, an unnecessary blank line is inserted before the first line inside pre. Could you check the patch?

#6 Updated by Go MAEDA 21 days ago

#7 Updated by Takenori TAKAKI 20 days ago

Go MAEDA wrote:

After applying the patch #8395#note-4, an unnecessary blank line is inserted before the first line inside pre. Could you check the patch?

Thank you for pointing out my patch's bug (#8395#note-6). I confirmed same trouble on my environment too...
To fix the bug, Necessary to change RedCloth3::OFFTAG_MATCH as below.

diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 6ffd7c78c..6894d4ee6 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1049,7 +1049,7 @@ class RedCloth3 < String
     end

     OFFTAGS = /(code|pre|kbd|notextile)/
-    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\W|\Z)/mi
+    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }(?:>| [^>]*>)))(.*?)(?=<\/?#{ OFFTAGS }\W|\Z)/mi
     OFFTAG_OPEN = /<#{ OFFTAGS }/
     OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
     HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m

Could you please try the new patch again?

#8 Updated by Go MAEDA 18 days ago

  • Status changed from Needs feedback to New
  • Target version changed from Candidate for next minor release to 3.4.7

LGTM. The patch can be applied to the trunk and 3.4-stable cleanly. Setting target version to 3.4.7.

#9 Updated by Marius BALTEANU 14 days ago

Attached a test case for this issue.

Another way to fix this is to add to the regex the word boundary (\b):

diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 6ffd7c7..56085ad 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1049,7 +1049,7 @@ class RedCloth3 < String
     end

     OFFTAGS = /(code|pre|kbd|notextile)/
-    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\W|\Z)/mi
+    OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }\b>)|(<#{ OFFTAGS }\b[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\b\W|\Z)/mi
     OFFTAG_OPEN = /<#{ OFFTAGS }/
     OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
     HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
@@ -1216,4 +1216,3 @@ class RedCloth3 < String
       text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "&lt;#{$1}#{'&gt;' unless $3.blank?}" }
     end
 end

#10 Updated by Marius BALTEANU 14 days ago

#11 Updated by Marius BALTEANU 14 days ago

#12 Updated by Go MAEDA 14 days ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

#13 Updated by Go MAEDA 14 days ago

  • Status changed from Resolved to Closed

Committed #8395#note-9. Thank you all for the contribution.

Also available in: Atom PDF