Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby equivalent to JavaScript’s encodeURIComponent that produces identical output? [duplicate]

Tags:

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

like image 455
Mo. Avatar asked May 18 '10 14:05

Mo.


People also ask

What is the difference between encodeURI and encodeURIComponent?

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.

What is encodeURIComponent Javascript?

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).

What is decodeURIComponent?

The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.


1 Answers

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?

like image 199
dierre Avatar answered Nov 01 '22 22:11

dierre