Ruby 2.4参考手册
URI
URI::Escape
用代码转义不安全字符的模块。
公共实例方法
decode(*arg)
别名为:unescape
encode(*arg)
别名为:escape
escape(*arg) Show source
概要
URI.escape(str [, unsafe])
Args
str
要替换的字符串。
unsafe
正则表达式匹配所有必须用代码替换的符号。默认使用UNSAFE
。当这个参数是一个字符串时,它表示一个字符集。
描述
转义字符串,用代码替换所有不安全的字符。
此方法已过时,不应使用。取而代之的是使用CGI.escape,URI.encode_www_form或URI.encode_www_form_component,具体取决于您的特定用例。
用法
require 'uri'
enc_uri = URI.escape("http://example.com/?a=\11\15")
p enc_uri
# => "http://example.com/?a=%09%0D"
p URI.unescape(enc_uri)
# => "http://example.com/?a=\t\r"
p URI.escape("@?@!", "!?")
# => "@%3F@%21"
# File lib/uri/common.rb, line 101
def escape(*arg)
warn "#{caller(1)[0]}: warning: URI.escape is obsolete" if $VERBOSE
DEFAULT_PARSER.escape(*arg)
end
另外别名为:encode
unescape(*arg) Show source
概要
URI.unescape(str)
Args
str
Unescapes字符串。
用法
require 'uri'
enc_uri = URI.escape("http://example.com/?a=\11\15")
p enc_uri
# => "http://example.com/?a=%09%0D"
p URI.unescape(enc_uri)
# => "http://example.com/?a=\t\r"
# File lib/uri/common.rb, line 127
def unescape(*arg)
warn "#{caller(1)[0]}: warning: URI.unescape is obsolete" if $VERBOSE
DEFAULT_PARSER.unescape(*arg)
end
另外别名为:decode
URI相关
Ruby 是一种面向对象、命令式、函数式、动态的通用编程语言,是世界上最优美而巧妙的语言。
主页 | https://www.ruby-lang.org/ |
源码 | https://github.com/ruby/ruby |
版本 | 2.4 |
发布版本 | 2.4.1 |