Hi is there an equivalent ruby method to JavaScript encodeURIComponent
method? i am using the URI.unescape(str)
but it recognizes the "£"
(after encodeURIComponent
it becomes "%C2%A3"
) as a "?"
sign. any solution's? thanks
The difference between encodeURI and encodeURIComponent is encodeURIComponent encodes the entire string, where encodeURI ignores protocol prefix ('http://') and domain name. encodeURIComponent is designed to encode everything, where encodeURI ignores a URL's domain related roots.
The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.
URI.escape(foo, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
found here: How do I raw URL encode/decode in JavaScript and Ruby to get the same values in both?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With