Ruby:decode_www_form_component失败,%编码无效



以下URL有效,但decode_www_form_component方法无法对其进行解码。

irb(main):001:0> url = "https://ru.wikipedia.org/wiki/%D0%A0%D0%B0%D0%B4%D0%BE%D0%BC%D1%8B%D1%81%D0%BB%D0%B5%D0%BD%D1%81%D0%BA%D0%B8%D0%B9,_%D0%95%D0%B2%D0%B3%D0%B5%D0%BD%D0%B8%D0%B9_%D0%92%D0%B5%D0%BD%D0%B8%D0%B0%D0%BC%D0%B"
irb(main):002:0> URI.decode_www_form_component(url)
Traceback (most recent call last):
1: from (irb):13
ArgumentError (invalid %-encoding (https://ru.wikipedia.org/wiki/%D0%A0%D0%B0%D0%B4%D0%BE%D0%BC%D1%8B%D1%81%D0%BB%D0%B5%D0%BD%D1%81%D0%BA%D0%B8%D0%B9,_%D0%95%D0%B)
2%D0%B3%D0%B5%D0%BD%D0%B8%D0%B9_%D0%92%D0%B5%D0%BD%D0%B8%D0%B0%D0%BC%D0%B)

知道如何避免这个错误吗?

我的错误,我没有看到URL无效,它被截断为200个字符。

irb(main):001:0> url = "https://ru.wikipedia.org/wiki/%D0%93%D0%BE%D0%BB%D1%83%D0%B1%D0%B5%D0%B2,_%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B5%D0%B9_%D0%9A%D0%BE%D0%BD%D1%81%D1%82%D0%B0%D0%BD%D1%82%D0%B8%D0%BD%D0%BE%D0%B2%D0%B8%D1%87"
irb(main):002:0> URI.decode_www_form_component(url)
=> "https://ru.wikipedia.org/wiki/Голубев,_Алексей_Константинович"

最新更新