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
1 Answer
Reset to default 19URI.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.