Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v2_1_10) is shown here.
escape(str, unsafe = @regexp[:UNSAFE])
public
Args
str |
String to make safe
|
unsafe |
Regexp to apply. Defaults to
self.regexp[:UNSAFE]
|
constructs a safe String from str,
removing unsafe characters, replacing them with codes.
# File lib/uri/common.rb, line 299
def escape(str, unsafe = @regexp[:UNSAFE])
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
end
str.gsub(unsafe) do
us = $&
tmp = ''
us.each_byte do |uc|
tmp << sprintf('%%%02X', uc)
end
tmp
end.force_encoding(Encoding::US_ASCII)
end