Project

General

Profile

Actions

Defect #20420

closed

auto_link in wiki_formatter fails

Added by Thomas Leichtfuß over 9 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Text formatting
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

Description

Environment:

sh: 1: darcs: not found
sh: 1: hg: not found
sh: 1: cvs: not found
sh: 1: bzr: not found
Environment:
  Redmine version                3.0.4.stable
  Ruby version                   1.9.3-p448 (2013-06-27) [i686-linux]
  Rails version                  4.2.3
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.8.10
  Git                            2.1.4
  Filesystem                     
Redmine plugins:
  redmine_ckeditor               1.1.0
  redmine_contacts               4.0.1
  redmine_contacts_helpdesk      3.0.0
  redmine_contacts_invoices      4.0.0
  redmine_finance                2.0.0

The error occures in context with the redmine_contacts and the redmine_ckeditor, but the failing code is lib/redmine/wiki_formatting.rb of the core-code.
To reproduce the error create a contact and add a note with the following content:

<p>%%[Gru&szlig;formel]%% Schuttenberg,<br />
<br />
vielen Dank f&uuml;r die Anfrage und das nette Gespr&auml;ch.<br />
<br />
Wie besprochen habe ich Ihnen eben einen Demozugang mit folgenden Zugangsdaten eingerichtet:<br />
<br />
URL: <a class="external" href="http://civihosting.systopia.de/">http://civihosting.systopia.de/</a><br />
Benutzername: XXXX<br />
Passwort: XXXXX<br />
<br />
Ich habe zus&auml;tzlich zu den Kernfunktionen wie besprochen nun zun&auml;chst folgende Module aktiviert:</p>

<ul>
    <li><b>Versand und Auswertung von Mailings (z.B. Newslettern) </b></li>
    <li><b>Mitgliederverwaltung </b></li>
    <li><b>Spendenverwaltung</b></li>
</ul>

<p>Es gibt dar&uuml;ber hinaus noch einige weitere Funktionen (z.B. ein <b> Veranstaltungs- und Kampagnenmanagement</b>), die ich aber aus Gr&uuml;nden der &Uuml;bersichtlichkeit zun&auml;chst nicht aktiviert habe - falls Sie diese auch testen wollen, sagen Sie gerne Bescheid.<br />
<br />
CiviCRM ist stark anpassungsf... "(weiter lesen)":/redmine/notes/88?project_id=systopia

This breaks the contact-view (not the view of the note) and produces the following log-message:

Started GET "/redmine/contacts/137?project_id=systopia" for 130.180.124.102 at 2015-07-27 14:53:12 +0200
Processing by ContactsController#show as HTML
  Parameters: {"project_id"=>"systopia", "id"=>"137"}
  Current user: thomas (id=8)
  Rendered plugins/redmine_contacts/app/views/contacts_tags/_tags_form.html.erb (3.0ms)
  Rendered plugins/redmine_contacts/app/views/contacts/_form_tags.html.erb (8.4ms)
  Rendered attachments/_form.html.erb (2.1ms)
  Rendered plugins/redmine_contacts/app/views/notes/_form.html.erb (6.7ms)
  Rendered plugins/redmine_contacts/app/views/notes/_add.html.erb (8.0ms)
  Rendered plugins/redmine_contacts/app/views/notes/_note_item.html.erb (20.1ms)
  Rendered plugins/redmine_contacts/app/views/contacts/_notes.html.erb (134.1ms)
  Rendered plugins/redmine_contacts/app/views/common/_contact_tabs.html.erb (136.6ms)
  Rendered plugins/redmine_contacts/app/views/contacts/show.html.erb within layouts/base (172.3ms)
Completed 500 Internal Server Error in 211ms (ActiveRecord: 10.8ms)

ActionView::Template::Error (undefined method `[]' for nil:NilClass):
    39:                 <% end %>
    40:                 </div>
    41:                 <div class="wiki note">
    42:                     <%= note_content(note_item) %>
    43:                     <%= auto_contacts_thumbnails(note_item) %>
    44:                     <%= render :partial => 'attachments/links', :locals => {:attachments => note_item.attachments, :options  => {}} if note_item.attachments.any? %>
    45:                 </div>
  lib/redmine/wiki_formatting.rb:125:in `block in auto_link!'
  lib/redmine/wiki_formatting.rb:116:in `auto_link!'
  lib/redmine/wiki_formatting.rb:71:in `to_html'
  app/helpers/application_helper.rb:574:in `textilizable'

Further investigations shows, that for some html-code-snippets (like the one above - I actually was not able to determine the exact combination of tags/words/formatting-stuff that leads to the error) the following code of lib/redmine/wiki_formatting.rb breaks:

115       def auto_link!(text)
116         text.gsub!(AUTO_LINK_RE) do
117           all, leading, proto, url, post = $&, $1, $2, $3, $6
118           if leading =~ /<a\s/i || leading =~ /![<>=]?/
119             # don't replace URLs that are already linked
120             # and URLs prefixed with ! !> !< != (textile images)
121             all
122           else
123             # Idea below : an URL with unbalanced parenthesis and
124             # ending by ')' is put into external parenthesis
125             if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
126               url=url[0..-2] # discard closing parenthesis from url
127               post = ")"+post # add closing parenthesis to post
128             end
129             content = proto + url
130             href = "#{proto=="www."?"http://www.":proto}#{url}" 
131             %(#{leading}<a class="external" href="#{ERB::Util.html_escape href}">#{ERB::Util.html_escape content}</a>#{post}).html_safe
132           end
133         end
134       end

The reason is, that the variables of line 117 (all, leading, proto, url, post) are empty, which leads to an exception in line 125.
I am not a ruby-programmer - but I wonder how it could be that $& is not set when the regular expression obviously matched? Otherwise we would not enter the loop at all, do we?

Actions #1

Updated by Thomas Leichtfuß over 9 years ago

I tested it now with ruby 2.0.0 and got the same error. Here is the new environment:

Environment:
  Redmine version                3.0.4.stable
  Ruby version                   2.0.0-p645 (2015-04-13) [i686-linux]
  Rails version                  4.2.3
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.8.10
  Git                            2.1.4
  Filesystem                     
Redmine plugins:
  redmine_ckeditor               1.1.0
  redmine_contacts               4.0.1
  redmine_contacts_helpdesk      3.0.0
  redmine_contacts_invoices      4.0.0
  redmine_finance                2.0.0
Actions #2

Updated by Thomas Leichtfuß over 9 years ago

Ok. I now see a little bit clearer:
The failure only occurs with notes that exceed a specific lenght. That is because of the following code in plugins/redmine_contacts/app/helpers/notes_helper.rb:

 82   def note_content(note)
 83     s = "" 
 84     if note.content.length > Note.cut_length
 85       s << textilizable(truncate(note.content, {:length => Note.cut_length, :omission => "... \"#{l(:label_crm_note_read_more)}\":#{url_for(:controller => 'notes', :action => 'show', :project_id => @project, :id => note)}" }))
 86     else
 87           s << textilizable(note, :content)
 88         end
 89         s.html_safe
 90   end

This leads for notes that exceed Note.cut_lenght to a weird formatted content. E.g. the above used html-snippet will become something like:

&lt;p&gt;&lt;b&gt;Hallo Schuttenberg&lt;/b&gt;,&lt;br /&gt;
&lt;br /&gt;
vielen Dank für die Anfrage und das nette Gespräch.&lt;br /&gt;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;
&lt;br /&gt;
URL: &lt;a class=&quot;external&quot; href=&quot;http://civihosting.systopia.de/&quot;&gt;http://civihosting.systopia.de/&lt;/a&gt;&lt;br /&gt;
Benutzername: XXXX&lt;br /&gt;
Passwort: XXXXX&lt;br /&gt;
&lt;br /&gt;
Ich habe zusätzlich zu den Kernfunktionen wie besprochen nun zunächst folgende Module aktiviert:&lt;/p&gt;

&lt;ul&gt;
        &lt;li&gt;&lt;b&gt;Versand und Auswertung von Mailings (z.B. Newslettern) &lt;/b&gt;&lt;/li&gt;
        &lt;li&gt;&lt;b&gt;Mitgliederverwaltung &lt;/b&gt;&lt;/li&gt;
        &lt;li&gt;&lt;b&gt;Spendenverwaltung&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Es gibt darüber hinaus noch einige weitere Funktionen (z.B. ein &lt;b&gt; Veranstaltungs- und Kampagnenmanagement&lt;/b&gt;), die ich aber aus Gründen ... &quot;(weiter lesen)&quot;:/redmine/notes/307?project_id=systopia

While this happens in redmine-3.0.4 it does not in 2.6.5. The textilizable-method in app/helpers/application_helper.rb has changed since 2.6.5.

So I still think that rubys gsub-method fails to handle the above string (it just must not enter the loop with an unset $&-variable). But the source of the strange formatting seems to be the interaction between the redmine-3.0.4-core-code and the redmine_contacts-plugin.
If now the textilizable-method must be fixed or the way it is called from the redmine_contacts-plugin, I do not know.

But for all who face the same problem - here is my dirty work-around:
Just increasing the @@cut_lenght in plugins/redmine_contacts/app/models/note.rb helps avoiding this issue.

Actions #3

Updated by Toshi MARUYAMA about 9 years ago

  • Status changed from New to Closed
  • Resolution set to Invalid

Please contact plugin author.

Actions #4

Updated by Dimitar (RedmineUP) almost 2 years ago

Hello Thomas,

This is Dimitar from the RedmineUP Support Team.

I see that you have some of our plugins on your list:

  redmine_contacts               4.0.1
  redmine_contacts_helpdesk      3.0.0
  redmine_contacts_invoices      4.0.0
  redmine_finance                2.0.0

May I ask - is the reported problem still appearing to your Redmine?

We look forward to hearing from you.

Best Regards,
Dimitar from the RedmineUP Support Team

Thomas Leichtfuß wrote:

Environment:

[...]

The error occures in context with the redmine_contacts and the redmine_ckeditor, but the failing code is lib/redmine/wiki_formatting.rb of the core-code.
To reproduce the error create a contact and add a note with the following content:

[...]

This breaks the contact-view (not the view of the note) and produces the following log-message:

[...]

Further investigations shows, that for some html-code-snippets (like the one above - I actually was not able to determine the exact combination of tags/words/formatting-stuff that leads to the error) the following code of lib/redmine/wiki_formatting.rb breaks:

[...]

The reason is, that the variables of line 117 (all, leading, proto, url, post) are empty, which leads to an exception in line 125.
I am not a ruby-programmer - but I wonder how it could be that $& is not set when the regular expression obviously matched? Otherwise we would not enter the loop at all, do we?

Actions #5

Updated by Thomas Leichtfuß almost 2 years ago

We are now using
  • redmine 4.2.7
  • redmine_contact 4.3.1

This issue seems to be solved for these versions.

Actions

Also available in: Atom PDF