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

Also available in: Atom PDF