26507_fix_attachment_links_with_@_in_file_name.patch

Marius BALTEANU, 2017-08-06 10:01

Download (1.97 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/unit/helpers/application_helper_test.rb
718 718
                 textilizable('attachment:test.txt', :attachments => [a1, a2])
719 719
  end
720 720

  
721
  def test_attachment_links_to_images_with_email_format_should_not_be_parsed
722
    attachment = Attachment.generate!(:filename => 'image@2x.png')
723

  
724
    with_settings :text_formatting => 'textile' do
725
      raw = "attachment:image@2x.png should not be parsed in image@2x.png"
726
      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>},
727
        textilizable(raw, :attachments => [attachment])
728
    end
729

  
730
    with_settings :text_formatting => 'markdown' do
731
      raw = "attachment:image@2x.png should not be parsed in image@2x.png"
732
      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>} ,
733
        textilizable(raw, :attachments => [attachment])
734
    end
735
  end
736

  
721 737
  def test_wiki_links
722 738
    User.current = User.find_by_login('jsmith')
723 739
    russian_eacape = CGI.escape(@russian_test)