ruby / rails相当于javascript decodeURIComponent?
发布时间:2020-12-17 04:19:16 所属栏目:百科 来源:网络整理
导读:我有一些内容(html)由于这个 javascript(从 this page)被编码并发送到我的rails应用程序: function encode_utf8_b64(string) {return window.btoa(unescape(encodeURIComponent(string)));} 相应的js代码将其恢复原状是这样的: function decode_utf8_b64(s
我有一些内容(html)由于这个
javascript(从
this page)被编码并发送到我的rails应用程序:
function encode_utf8_b64(string) { return window.btoa(unescape(encodeURIComponent(string))); } 相应的js代码将其恢复原状是这样的: function decode_utf8_b64(string) { return decodeURIComponent(escape(window.atob(string))); } 我的问题是,在decodeURIComponent()的ruby中是否有相应的东西?到目前为止,我有这个让它成为出路的一部分,但我错过了decodeURIComponent的最后一步: CGI::escape(Base64.decode64(string)) 解决方法
URI.unescape可能会有所帮助:
def decode_utf8_b64(string) URI.unescape(CGI::escape(Base64.decode64(string))) end 你必须添加必要的rubygem: require 'uri' 我在ruby 1.9.2上测试了这个. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |