Mercurial > hg > soundsoftware-site
diff app/helpers/attachments_helper.rb @ 119:8661b858af72
* Update to Redmine trunk rev 4705
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 14:12:06 +0000 |
parents | 513646585e45 |
children | cbce1fd3b1b7 |
line wrap: on
line diff
--- a/app/helpers/attachments_helper.rb Fri Nov 19 14:05:24 2010 +0000 +++ b/app/helpers/attachments_helper.rb Thu Jan 13 14:12:06 2011 +0000 @@ -29,6 +29,18 @@ end def to_utf8(str) - str + if str.respond_to?(:force_encoding) + str.force_encoding('UTF-8') + return str if str.valid_encoding? + else + return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii + end + + begin + Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] + rescue Iconv::InvalidEncoding + # "UTF-8//IGNORE" is not supported on some OS + str + end end end