简体   繁体   English

错误:将Ruby 1.8.7升级到Ruby 1.9.2后,UTF-8中的字节序列无效

[英]error: invalid byte sequence in UTF-8 after upgrading ruby 1.8.7 to ruby 1.9.2

I had my app running in ruby 1.8.7 and rails 3.0.11 ,I upgraded it with 1.9.2 ruby and rails 3.2.2. 我的应用程序在ruby 1.8.7和rails 3.0.11中运行,我用1.9.2 ruby​​和rails 3.2.2对其进行了升级。 it has a utf convertor like this 它有这样的utf转换器

@utf8_converter = Iconv.new('UTF-8//IGNORE', 'UTF-8')
......  
......
def utf8(untrusted_string)
valid_string = @utf8_converter.iconv(untrusted_string + ' ')[0..-2]
return valid_string

Unto my Understanding Iconv doesn't support ruby 1.9.2. 据我所知Iconv不支持ruby 1.9.2。 how can make it run? 如何使其运行?

Thanks 谢谢

I believe this is should get you on the right track: 我相信这应该可以使您走上正确的轨道:

def utf8(untrusted_string) 
  valid_string = (untrusted_string + ' ').encode('utf-8')
  return valid_string
end

The @utf8_converter variable is no longer needed as Iconv is deprecated, so you can get away with just your utf8 method. 由于不推荐使用Iconv,因此不再需要@utf8_converter变量,因此您可以只使用utf8方法。

Ruby 1.9.2 does support Iconv , if you are using ruby through rvm, you should install it in the following way, Ruby 1.9.2确实支持Iconv ,如果您通过rvm使用ruby,则应通过以下方式安装它:

$ rvm pkg install iconv
$ rvm reinstall 1.9.2 --with-iconv-dir=$rvm_path/usr

Read more here 在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Ruby升级到1.9.2后,Rails查看错误“US-ASCII中的无效字节序列”错误 - Rails view error “invalid byte sequence in US-ASCII” error after upgrading Ruby to 1.9.2 Ruby on Rails在UTF-8中的无效字节序列 - Ruby on Rails invalid byte sequence in UTF-8 Rails 2.3和ruby 1.9中的无效字节序列utf-8错误 - invalid byte sequence utf-8 error in rails 2.3 and ruby 1.9 Ruby on Rails - 来自Paypal的params:utf-8中的无效字节序列 - Ruby on Rails - params from Paypal : invalid byte sequence in utf-8 Ruby 中单引号的 UTF-8 中的无效字节序列 - invalid byte sequence in UTF-8 for single quote in Ruby ArgumentError(UTF-8中无效的字节序列):Ruby 1.9.3渲染视图 - ArgumentError (invalid byte sequence in UTF-8): Ruby 1.9.3 render view UTF-8中的Ruby on Rails无效字节序列(ArgumentError) - Ruby on Rails invalid byte sequence in UTF-8 (ArgumentError) 由于机器人,Ruby on Rails“UTF-8 中的字节序列无效” - Ruby on Rails “invalid byte sequence in UTF-8” due to bot 有没有办法清除 Ruby 中“UTF-8 中的无效字节序列”错误的文件? - Is there a way to clean a file of “invalid byte sequence in UTF-8” errors in Ruby? Ruby'to_json'抛出ArgumentError:UTF-8中无效的字节序列 - Ruby 'to_json' throws ArgumentError: invalid byte sequence in UTF-8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM