jjzjj

batch_encode_plus

全部标签

ruby - Ruby 中的 url_encode

我读了thedocumentationofurl_encode.是否有一张表格可以使用url_encode准确地告诉我哪个字符被编码成什么? 最佳答案 再培训局url_encode可以调整:defurl_encode(s)s.to_s.dup.force_encoding("ASCII-8BIT").gsub(%r[^a-zA-Z0-9_\-.]/){sprintf("%%%02X",$&.unpack("C")[0])}end到:defurl_encode(s,regex=%r[^a-zA-Z0-9_\-.]/)s.to_s.du

ruby - 安装 RDoc 文档时出错 : incompatible encoding regexp match

上周,在一些gem安装或gem更新操作中,我收到了与这些类似的错误:ERROR:Whilegeneratingdocumentationforsinatra-1.3.1...MESSAGE:errorgeneratingC:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/doc/sinatra-1.3.1/rdoc/README_de_rdoc.html:incompatibleencodingregexpmatch(UTF-8regexpwithIBM437string)(Encoding::CompatibilityError)类似的:E

ruby-on-rails - rails : encoding woes with serialized hashes despite UTF8

我刚刚从ruby​​1.9.2更新到ruby​​1.9.3p0(2011-10-30修订版33570)。我的Rails应用程序使用postgresql作为其数据库后端。系统区域设置为UTF8,数据库编码也是如此。Rails应用程序的默认编码也是UTF8。我有中国用户输入汉字和英文字符。字符串存储为UTF8编码字符串。rails版本:3.0.9自更新以来,数据库中的一些现有中文字符串不再正确显示。这不会影响所有字符串,只会影响那些属于序列化哈希的字符串。存储为普通字符串的所有其他字符串看起来仍然是正确的。示例:这是一个序列化的散列,在数据库中存储为UTF8字符串:broken="---!

ruby - String#encode 未修复 "invalid byte sequence in UTF-8"错误

我知道有很多关于此错误的类似问题,而且我已经尝试了很多,但都没有成功。我遇到的问题涉及字节\xA1并且正在抛出ArgumentError:invalidbytesequenceinUTF-8我尝试了以下但没有成功:"\xA1".encode('UTF-8',:undef=>:replace,:invalid=>:replace,:replace=>"").sub('','')"\xA1".encode('UTF-8',:undef=>:replace,:invalid=>:replace,:replace=>"").force_encoding('UTF-8').sub('','')"

ruby-on-rails - Ruby 1.8.7(或 Rails 2.x)中的 String.force_encoding()

是否有在Ruby1.8.7(或Rails2.x)中使用String.force_encoding()的解决方案,以便它像在Ruby1.9中一样工作?我读了一些关于requireactive_support的内容,但这不起作用$>gem列表--本地|grep'rails\|activesupport'activesupport(3.0.3,2.3.8,2.3.5)rails(2.3.8,2.3.5)$>ruby-vruby1.8.7(2010-08-16patchlevel302)[i686-darwin10.4.0]$>rails-vRails2.3.8IRB:>require"rub

ruby 1.9 : Regular Expressions with unknown input encoding

在输入编码未知的Ruby1.9中,是否有一种公认的方法来处理正则表达式?假设我的输入恰好是UTF-16编码的:x="foobarbaz"y=x.encode('UTF-16LE')re=/(.*)/x.match(re)=>#bar"1:"bar">y.match(re)Encoding::CompatibilityError:incompatibleencodingregexpmatch(US-ASCIIregexpwithUTF-16LEstring)我目前的方法是在内部使用UTF-8并在必要时重新编码(副本)输入:ify.methods.include?(:encode)#Rub

ruby - Ruby 中的 URI.escape 和 URI.encode 有什么区别?

我试图找出URI.escape和URI.encode之间的区别ruby。两者都没有按照我的意愿进行,即对URL进行完全编码。例如,我希望http://my.web.com为http%3A%2F%2Fmy%2Eweb%2Ecom 最佳答案 没有区别。在Ruby1.9.3中encodeissimplyanaliasforescape.[编辑]请注意,这些方法允许对字符的“不安全”描述符进行编码:URI.encode('http://my.web.com',/\W/)#=>"http%3A%2F%2Fmy%2Eweb%2Ecom"谢谢@m

使用 Base64.encode 时的 Ruby 字符编码

查看Ruby的Base64.encode的源代码,我无法确定字符串转换为哪种字符编码,如果有的话,在Base64中对该数据进行编码之前。以Base64编码的Utf-8字符串与以Base64编码的Utf-16字符串有很大不同。Ruby是否对此操作做出任何promise? 最佳答案 在base64中编码和解码utf-8字符串的示例:text="intérnalionálização"=>"intérnalionálização"text.encoding=>#encoded=Base64.encode64(text)=>"aW50w6l

ruby-on-rails - Encoding::UndefinedConversionError 写入二进制文件时

我有一个网站需要加密和存储上传到服务器的二进制文件。上传和存储工作正常,但在尝试写入加密文件时出现此错误:Encoding::UndefinedConversionError("\xDD"fromASCII-8BITtoUTF-8):导致它的代码如下所示:fd_in=IO.sysopen(self[:name].tempfile.path,"rb")file_in=IO.open(fd_in)fd_out=IO.sysopen(self[:name].tempfile.path+".encrypted","wb")file_out=IO.open(fd_out)cipher=OpenS

ruby-on-rails - rails : Plus sign in GET-Request replaced by space

在Rails3(Ruby1.9.2)中我发送一个请求StartedGET"/controller/action?path=/41_+"但是参数列表是这样的:{"path"=>"/41_","controller"=>"controller","action"=>"action"}这里出了什么问题?-、*或.符号工作正常,只是+将被空格替换。 最佳答案 这是正常的URL编码,theplussignisashorthandforaspace:Withinthequerystring,theplussignisreservedasshor