我正在使用URI.encode生成 HTML 数据 URL:
visit "data:text/html,#{URI::encode(html)}"
Run Code Online (Sandbox Code Playgroud)
升级到 Ruby 2.7.1 后,解释器开始警告:
warning: URI.escape is obsolete
Run Code Online (Sandbox Code Playgroud)
推荐的替代品是CGI.escape和URI.encode_www_form_component。然而,他们并没有做同样的事情:
2.7.1 :007 > URI.escape '<html>this and that</html>'
(irb):7: warning: URI.escape is obsolete
=> "%3Chtml%3Ethis%20and%20that%3C/html%3E"
2.7.1 :008 > CGI.escape '<html>this and that</html>'
=> "%3Chtml%3Ethis+and+that%3C%2Fhtml%3E"
2.7.1 :009 > URI.encode_www_form_component '<html>this and that</html>'
=> "%3Chtml%3Ethis+and+that%3C%2Fhtml%3E"
Run Code Online (Sandbox Code Playgroud)
这些轻微编码差异的结果 - html 页面,其中空格被替换为+. 我的问题是 -URI.encode这个用例有什么好的替代品?
ruby ×1