Project

General

Profile

Defect #27968 » 0001-do-not-recognize-hires-images-as-email-addresses.patch

Marius BĂLTEANU, 2018-04-29 09:01

View differences:

lib/redmine/wiki_formatting.rb
184 184
        html.gsub!(%r{\battachment:<a(\sclass="email")? href="mailto:(.*?)">(.*?)</a>}) do
185 185
          "attachment:#{$2}"
186 186
        end
187
        # restore hires images which are misrecognized as email address eg. [printscreen@2x.png]
188
        html.gsub!(%r{<a(\sclass="email")? href="mailto:[^"]+@\dx\.(bmp|gif|jpg|jpe|jpeg|png)">(.*?)</a>}) do
189
          "#{$3}"
190
        end
187 191
        html
188 192
      end
189 193
    end
test/helpers/application_helper_test.rb
697 697

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

  
704 704
    with_settings :text_formatting => 'markdown' do
705 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>} ,
706
      assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}/image@2x.png">image@2x.png</a> should not be parsed in image@2x.png</p>} ,
707 707
        textilizable(raw, :attachments => [attachment])
708 708
    end
709 709
  end
test/unit/lib/redmine/wiki_formatting_test.rb
77 77
    end
78 78
  end
79 79

  
80
  def test_hires_images_should_not_be_recognized_as_email_addresses
81
    raw = <<-DIFF
82
Image: logo@2x.png
83
    DIFF
84

  
85
    expected = <<-EXPECTED
86
<p>Image: logo@2x.png</p>
87
    EXPECTED
88

  
89
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
90
  end
91

  
80 92
  def test_cache_key_for_saved_object_should_no_be_nil
81 93
    assert_not_nil Redmine::WikiFormatting.cache_key_for('textile', 'Text', Issue.find(1), :description)
82 94
  end
    (1-1/1)