最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rubyrails equivalent to javascript decodeURIComponent? - Stack Overflow

programmeradmin0浏览0评论

I have some content (html) that is being encoded as a result of this javascript (from this page) and sent to my rails application:

function encode_utf8_b64(string) {
return window.btoa(unescape(encodeURIComponent(string)));
}

The correspond js code to get it back to original is this:

function decode_utf8_b64(string) {
return decodeURIComponent(escape(window.atob(string)));
}

My question is, is there an equivalent in ruby of decodeURIComponent()? So far I have this that gets it part of the way out, but I'm missing the last step of decodeURIComponent:

CGI::escape(Base64.decode64(string))

I have some content (html) that is being encoded as a result of this javascript (from this page) and sent to my rails application:

function encode_utf8_b64(string) {
return window.btoa(unescape(encodeURIComponent(string)));
}

The correspond js code to get it back to original is this:

function decode_utf8_b64(string) {
return decodeURIComponent(escape(window.atob(string)));
}

My question is, is there an equivalent in ruby of decodeURIComponent()? So far I have this that gets it part of the way out, but I'm missing the last step of decodeURIComponent:

CGI::escape(Base64.decode64(string))
Share Improve this question asked Jun 23, 2011 at 17:07 bobfet1bobfet1 1,63321 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

URI.unescape could probably help:

def decode_utf8_b64(string)
  URI.unescape(CGI::escape(Base64.decode64(string)))
end

you have to add the necessary rubygem too:

require 'uri'

I've tested this on ruby 1.9.2.

发布评论

评论列表(0)

  1. 暂无评论