@@ -29,19 +29,7 module AttachmentsHelper | |||
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def to_utf8(str) |
|
32 | if str.respond_to?(:force_encoding) | |
|
33 | str.force_encoding('UTF-8') | |
|
34 | return str if str.valid_encoding? | |
|
35 | else | |
|
36 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |
|
37 | end | |
|
38 | ||
|
39 | begin | |
|
40 | Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] | |
|
41 | rescue Iconv::InvalidEncoding | |
|
42 | # "UTF-8//IGNORE" is not supported on some OS | |
|
43 | str | |
|
44 | end | |
|
32 | Redmine::CodesetUtil.to_utf8_by_setting(str) | |
|
45 | 33 | end |
|
46 | 34 | |
|
47 | 35 | def render_api_attachment(attachment, api) |
@@ -52,19 +52,21 class AttachmentsControllerTest < ActionController::TestCase | |||
|
52 | 52 | end |
|
53 | 53 | end |
|
54 | 54 | |
|
55 |
def test_show_diff_ |
|
|
56 | ['inline', 'sbs'].each do |dt| | |
|
57 | # 060719210727_changeset_iso8859-1.diff | |
|
58 | get :show, :id => 5, :type => dt | |
|
59 | assert_response :success | |
|
60 | assert_template 'diff' | |
|
61 | assert_equal 'text/html', @response.content_type | |
|
62 | assert_tag 'th', | |
|
63 | :attributes => {:class => /filename/}, | |
|
64 | :content => /issues_controller.rb\t\(rvision 1484\)/ | |
|
65 | assert_tag 'td', | |
|
66 | :attributes => {:class => /line-code/}, | |
|
67 | :content => /Demande cre avec succs/ | |
|
55 | def test_show_diff_replcace_cannot_convert_content | |
|
56 | with_settings :repositories_encodings => 'UTF-8' do | |
|
57 | ['inline', 'sbs'].each do |dt| | |
|
58 | # 060719210727_changeset_iso8859-1.diff | |
|
59 | get :show, :id => 5 | |
|
60 | assert_response :success | |
|
61 | assert_template 'diff' | |
|
62 | assert_equal 'text/html', @response.content_type | |
|
63 | assert_tag 'th', | |
|
64 | :attributes => {:class => "filename"}, | |
|
65 | :content => /issues_controller.rb\t\(r\?vision 1484\)/ | |
|
66 | assert_tag 'td', | |
|
67 | :attributes => {:class => /line-code/}, | |
|
68 | :content => /Demande cr\?\?e avec succ\?s/ | |
|
69 | end | |
|
68 | 70 | end |
|
69 | 71 | end |
|
70 | 72 | |
@@ -96,22 +98,24 class AttachmentsControllerTest < ActionController::TestCase | |||
|
96 | 98 | :sibling => { :tag => 'td', :content => /#{str_japanese}/ } |
|
97 | 99 | end |
|
98 | 100 | |
|
99 |
def test_show_text_file_ |
|
|
101 | def test_show_text_file_replcace_cannot_convert_content | |
|
100 | 102 | set_tmp_attachments_directory |
|
101 | a = Attachment.new(:container => Issue.find(1), | |
|
102 | :file => uploaded_test_file("iso8859-1.txt", "text/plain"), | |
|
103 | :author => User.find(1)) | |
|
104 | assert a.save | |
|
105 | assert_equal 'iso8859-1.txt', a.filename | |
|
106 | ||
|
107 | get :show, :id => a.id | |
|
108 | assert_response :success | |
|
109 | assert_template 'file' | |
|
110 | assert_equal 'text/html', @response.content_type | |
|
111 | assert_tag :tag => 'th', | |
|
112 | :content => '7', | |
|
113 | :attributes => { :class => 'line-num' }, | |
|
114 | :sibling => { :tag => 'td', :content => /Demande cre avec succs/ } | |
|
103 | with_settings :repositories_encodings => 'UTF-8' do | |
|
104 | a = Attachment.new(:container => Issue.find(1), | |
|
105 | :file => uploaded_test_file("iso8859-1.txt", "text/plain"), | |
|
106 | :author => User.find(1)) | |
|
107 | assert a.save | |
|
108 | assert_equal 'iso8859-1.txt', a.filename | |
|
109 | ||
|
110 | get :show, :id => a.id | |
|
111 | assert_response :success | |
|
112 | assert_template 'file' | |
|
113 | assert_equal 'text/html', @response.content_type | |
|
114 | assert_tag :tag => 'th', | |
|
115 | :content => '7', | |
|
116 | :attributes => { :class => 'line-num' }, | |
|
117 | :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ } | |
|
118 | end | |
|
115 | 119 | end |
|
116 | 120 | |
|
117 | 121 | def test_show_text_file_should_send_if_too_big |
General Comments 0
You need to be logged in to leave comments.
Login now