26507_fix_attachment_links_with_@_in_file_name.patch

Marius BALTEANU, 2018-04-08 09:26

Download (1.95 KB)

View differences:

lib/redmine/wiki_formatting.rb
180 180
        html.gsub!(%r{\buser:<a(\sclass="email")? href="mailto:(.*?)">(.*?)<\/a>}) do
181 181
          "user:#{$2}"
182 182
        end
183
        # restore attachments links with @ in file name eg. [attachment:image@2x.png]
184
        html.gsub!(%r{\battachment:<a(\sclass="email")? href="mailto:(.*?)">(.*?)</a>}) do
185
          "attachment:#{$2}"
186
        end
183 187
        html
184 188
      end
185 189
    end
test/helpers/application_helper_test.rb
692 692
                 textilizable('attachment:test.txt', :attachments => [a1, a2])
693 693
  end
694 694

  
695
  def test_attachment_links_to_images_with_email_format_should_not_be_parsed
696
    attachment = Attachment.generate!(:filename => 'image@2x.png')
697

  
698
    with_settings :text_formatting => 'textile' do
699
      raw = "attachment:image@2x.png should not be parsed in image@2x.png"
700
      assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}/image@2x.png">image@2x.png</a> should not be parsed in <a class="email" href="mailto:image@2x.png">image@2x.png</a></p>},
701
        textilizable(raw, :attachments => [attachment])
702
    end
703

  
704
    with_settings :text_formatting => 'markdown' do
705
      raw = "attachment:image@2x.png should not be parsed in image@2x.png"
706
      assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}/image@2x.png">image@2x.png</a> should not be parsed in <a href="mailto:image@2x.png">image@2x.png</a></p>} ,
707
        textilizable(raw, :attachments => [attachment])
708
    end
709
  end
710

  
695 711
  def test_wiki_links
696 712
    User.current = User.find_by_login('jsmith')
697 713
    russian_eacape = CGI.escape(@russian_test)