<分区>
您好,是否有与 JavaScript encodeURIComponent
方法等效的 ruby 方法?我正在使用 URI.unescape(str)
但它可以识别 "£"
(在 encodeURIComponent
之后它变成了 "%C2% A3"
) 作为 "?"
符号。任何解决方案?谢谢
<分区>
您好,是否有与 JavaScript encodeURIComponent
方法等效的 ruby 方法?我正在使用 URI.unescape(str)
但它可以识别 "£"
(在 encodeURIComponent
之后它变成了 "%C2% A3"
) 作为 "?"
符号。任何解决方案?谢谢
最佳答案
URI.escape(foo, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
在这里找到:How do I raw URL encode/decode in JavaScript and Ruby to get the same values in both?
自上次发布以来,URI.escape 已过时。根据建议的评论,现在使用:ERB::Util.url_encode
或 CGI.escape
关于javascript - Ruby 相当于 JavaScript 的 encodeURIComponent 产生相同的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2858345/