Method: Bundler::URI::RFC2396_Parser#escape
- Defined in:
- lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
permalink #escape(str, unsafe = ) ⇒ Object
:call-seq:
escape( str )
escape( str, unsafe )
Args
str
-
String to make safe
unsafe
-
Regexp to apply. Defaults to
self.regexp[:UNSAFE]
Description
Constructs a safe String from str
, removing unsafe characters, replacing them with codes.
287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb', line 287 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 |