summaryrefslogtreecommitdiff
path: root/lib/uri
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-13 02:02:24 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-13 02:02:24 +0000
commit31f8181095ad815fa9fba25a10518bd46772c3ea (patch)
tree4f3725766fb4e6cf945de33f4cb0a1b10a8ca139 /lib/uri
parent03ab81258512ed3ddc46c7e01f66fc3252e22c45 (diff)
* lib/uri/common.rb (escape): regard second argument as a character set. [ruby-dev:27692]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/uri')
-rw-r--r--lib/uri/common.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 2263fbddde..f74f0eb2e1 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -261,6 +261,7 @@ module URI
# +unsafe+::
# Regexp that matches all symbols that must be replaced with codes.
# By default uses <tt>REGEXP::UNSAFE</tt>.
+ # When this argument is a String, it represents a character set.
#
# == Description
#
@@ -277,10 +278,13 @@ module URI
# p URI.unescape(enc_uri)
# # => "http://example.com/?a=\t\r"
#
+ # p URI.escape("@?@!", "!?")
+ # # => "@%3F@%21"
+ #
def escape(str, unsafe = UNSAFE)
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
- unsafe = Regexp.new(Regexp.quote(unsafe), false, 'N')
+ unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false, 'N')
end
str.gsub(unsafe) do |us|
tmp = ''