Ruby equivalent to JavaScript’s encodeURIComponent that produces identical output?(Ruby等同于生成相同输出的JavaScript的encodeURIComponent吗?)
问题描述
Hi有没有与JAVASCRIPTencodeURIComponent
方法等价的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?
这篇关于Ruby等同于生成相同输出的JavaScript的encodeURIComponent吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!