Skip to content

Instantly share code, notes, and snippets.

@rcarver
Created February 18, 2009 19:36
Show Gist options
  • Save rcarver/66498 to your computer and use it in GitHub Desktop.
Save rcarver/66498 to your computer and use it in GitHub Desktop.
The difference between CGI.escape and URI.escape
require 'uri'
require 'cgi'
puts ["i", "i.chr", "URI.escape", "CGI.escape"].collect { |x| x.inspect }.join("\t")
(0..255).each do |i|
chr = i.chr
cgi = CGI.escape(chr)
uri = URI.escape(chr)
puts [i, chr, uri, cgi].collect { |x| x.inspect }.join("\t") if cgi != uri
end
"i" "i.chr" "URI.escape" "CGI.escape"
32 " " "%20" "+"
33 "!" "!" "%21"
36 "$" "$" "%24"
38 "&" "&" "%26"
39 "'" "'" "%27"
40 "(" "(" "%28"
41 ")" ")" "%29"
42 "*" "*" "%2A"
43 "+" "+" "%2B"
44 "," "," "%2C"
47 "/" "/" "%2F"
58 ":" ":" "%3A"
59 ";" ";" "%3B"
61 "=" "=" "%3D"
63 "?" "?" "%3F"
64 "@" "@" "%40"
91 "[" "[" "%5B"
93 "]" "]" "%5D"
126 "~" "~" "%7E"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment