Skip to content

Commit

Permalink
Add (en|de)code_query_component.
Browse files Browse the repository at this point in the history
These functions encode values in query components of uri's
(Much like CGI::encode, but without mangling valid + ) This is to deal with [[M+_Fonts]]
  • Loading branch information
hartman committed Jan 6, 2010
1 parent 0c3edca commit 7940804
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/controllers/application.rb
Expand Up @@ -22,4 +22,21 @@ def current_name
@title || "Wikipedia"
end

## URI helpers
#
# Encode a query part. Much like CGI:escape, but retains +
# For ?title=http:// --> ?title=http%3A%2F%2F
def encode_query_component(value)
URI::escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

def decode_query_component(value)
URI::unescape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

# URLs printed in HTML need & -> &
def url_to_html(url)
CGI::escapeHTML(url)
end

end

0 comments on commit 7940804

Please sign in to comment.