Never been to DZone Snippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
About this user
Zeke Sikelianos
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total
RSS
This example will show you how to escape and un-escape a value to be included in a URI and within HTML.
require 'cgi'
name = "ruby?"
value = "yes"
url = "http://example.com/?" + CGI.escape(name) + '=' + CGI.escape(value) + "&var=T"
html = %(<a href="#{CGI.escapeHTML(url)}">example</a>)
name_encoded = html.match(/http:([^"]+)/)[0]
href = CGI.unescapeHTML(name_encoded)
query = href.match(/\?(.*)$/)[1]
pairs = query.split('&')
name, value = pairs[0].split('=').map{|v| CGI.unescape(v)}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total
RSS