@@ -29,19 +29,7 module AttachmentsHelper | |||||
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def to_utf8(str) |
|
31 | def to_utf8(str) | |
32 | if str.respond_to?(:force_encoding) |
|
32 | Redmine::CodesetUtil.to_utf8_by_setting(str) | |
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 |
|
|||
45 | end |
|
33 | end | |
46 |
|
34 | |||
47 | def render_api_attachment(attachment, api) |
|
35 | def render_api_attachment(attachment, api) |
@@ -52,19 +52,21 class AttachmentsControllerTest < ActionController::TestCase | |||||
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 |
def test_show_diff_ |
|
55 | def test_show_diff_replcace_cannot_convert_content | |
56 | ['inline', 'sbs'].each do |dt| |
|
56 | with_settings :repositories_encodings => 'UTF-8' do | |
57 | # 060719210727_changeset_iso8859-1.diff |
|
57 | ['inline', 'sbs'].each do |dt| | |
58 | get :show, :id => 5, :type => dt |
|
58 | # 060719210727_changeset_iso8859-1.diff | |
59 | assert_response :success |
|
59 | get :show, :id => 5 | |
60 | assert_template 'diff' |
|
60 | assert_response :success | |
61 | assert_equal 'text/html', @response.content_type |
|
61 | assert_template 'diff' | |
62 | assert_tag 'th', |
|
62 | assert_equal 'text/html', @response.content_type | |
63 | :attributes => {:class => /filename/}, |
|
63 | assert_tag 'th', | |
64 | :content => /issues_controller.rb\t\(rvision 1484\)/ |
|
64 | :attributes => {:class => "filename"}, | |
65 | assert_tag 'td', |
|
65 | :content => /issues_controller.rb\t\(r\?vision 1484\)/ | |
66 | :attributes => {:class => /line-code/}, |
|
66 | assert_tag 'td', | |
67 | :content => /Demande cre avec succs/ |
|
67 | :attributes => {:class => /line-code/}, | |
|
68 | :content => /Demande cr\?\?e avec succ\?s/ | |||
|
69 | end | |||
68 | end |
|
70 | end | |
69 | end |
|
71 | end | |
70 |
|
72 | |||
@@ -96,22 +98,24 class AttachmentsControllerTest < ActionController::TestCase | |||||
96 | :sibling => { :tag => 'td', :content => /#{str_japanese}/ } |
|
98 | :sibling => { :tag => 'td', :content => /#{str_japanese}/ } | |
97 | end |
|
99 | end | |
98 |
|
100 | |||
99 |
def test_show_text_file_ |
|
101 | def test_show_text_file_replcace_cannot_convert_content | |
100 | set_tmp_attachments_directory |
|
102 | set_tmp_attachments_directory | |
101 | a = Attachment.new(:container => Issue.find(1), |
|
103 | with_settings :repositories_encodings => 'UTF-8' do | |
102 | :file => uploaded_test_file("iso8859-1.txt", "text/plain"), |
|
104 | a = Attachment.new(:container => Issue.find(1), | |
103 | :author => User.find(1)) |
|
105 | :file => uploaded_test_file("iso8859-1.txt", "text/plain"), | |
104 | assert a.save |
|
106 | :author => User.find(1)) | |
105 | assert_equal 'iso8859-1.txt', a.filename |
|
107 | assert a.save | |
106 |
|
108 | assert_equal 'iso8859-1.txt', a.filename | ||
107 | get :show, :id => a.id |
|
109 | ||
108 | assert_response :success |
|
110 | get :show, :id => a.id | |
109 | assert_template 'file' |
|
111 | assert_response :success | |
110 | assert_equal 'text/html', @response.content_type |
|
112 | assert_template 'file' | |
111 | assert_tag :tag => 'th', |
|
113 | assert_equal 'text/html', @response.content_type | |
112 | :content => '7', |
|
114 | assert_tag :tag => 'th', | |
113 | :attributes => { :class => 'line-num' }, |
|
115 | :content => '7', | |
114 | :sibling => { :tag => 'td', :content => /Demande cre avec succs/ } |
|
116 | :attributes => { :class => 'line-num' }, | |
|
117 | :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ } | |||
|
118 | end | |||
115 | end |
|
119 | end | |
116 |
|
120 | |||
117 | def test_show_text_file_should_send_if_too_big |
|
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