Module | URI |
In: |
lib/simpy.rb
|
Properly escape strings that will be included in a URL
str: | The string to transform |
Ruby’s built-in URL encoding method ignores symbols like equals and ampersand by design. Since this method properly encodes symbols that have syntactic relevance in URLs, it is not intended for use on strings that contain complete URLs.
{"a" => "test 1", "b" => "test 2"}.map {|x,y| "#{x}=#{URI.esc y}"}.join "&" # => "a=test%201&b=test%202"
# File lib/simpy.rb, line 95 95: def URI.esc str 96: URI.encode(str.to_s).gsub("&", "%26").gsub("=", "%3D") 97: end