gpt4 book ai didi

ruby - 使用 Mechanize 重定向到错误的 URI 会引发无效的 URI 错误

转载 作者:行者123 更新时间:2023-12-04 16:22:32 24 4
gpt4 key购买 nike

我试图与一个设计糟糕的网络服务器通信,但我仍然想处理它。问题是,当我提交登录表单时,它会尝试在 URI 中嵌入消息,这会导致 URI 库停止。

服务器将我重定向到

/path/ConvolutedNameForMenuPage.menu?name=bmenu.P_MainMnu&msg=WELCOME+<b>Welcome,+Jonathan+Allard,+to+our+poorly+designed+Administrative+Systems!<%2Fb>Dec+07,+201102%3A27+PM

没错,它试图在重定向 URI 中向我传递未解析的 HTML 代码,我应该请求它以将其取回。嘘,标准!

现在 URI 库,显然被这种糟糕的做法激怒了,惊呼
URI::InvalidURIError: bad URI(is not URI?): /path/ConvolutedNameForMenuPage.menu?name=bmenu.P_MainMnu&msg=WELCOME+<b>Welcome,+Jonathan+Allard,+to+our+poorly+designed+Administrative+Systems!<%2Fb>Dec+07,+201102%3A27+PM   from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/uri/generic.rb:1202:in `rescue in merge'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/uri/generic.rb:1199:in `merge'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mechanize-2.0.1/lib/mechanize/page/meta_refresh.rb:32:in `parse'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mechanize-2.0.1/lib/mechanize/page/meta_refresh.rb:41:in `from_node'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mechanize-2.0.1/lib/mechanize/page.rb:282:in `block in meta_refresh'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node_set.rb:239:in `block in each'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node_set.rb:238:in `upto'
from /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node_set.rb:238:in `each'

我感受到你的痛苦, URI

现在,我如何捕获这个,正确解析 URI(或完全删除它)并提交回来,好像什么也没发生?或者这是 URI 和 Mechanize 之间的某个错误?

最佳答案

在对代码进行了一些挖掘之后,我找到了问题的来源。

正如我在 #177 中解释的那样:

in /lib/mechanize/page/meta_refresh.rb:40

class Mechanize::Page::MetaRefresh

def self.parse content, base_uri
return unless content =~ CONTENT_REGEXP

delay, refresh_uri = $1, $3

dest = base_uri
dest += refresh_uri if refresh_uri # Oops!

return delay, dest
end

The referenced line will raise URI::InvalidURIError if refresh_uri contains illegal symbols (such as <). I don't quite know where the sanitize should be done though.



URI#merge 我的错误日志隐藏在 += 中oops 行上的运算符,如果您想知道的话。

关于ruby - 使用 Mechanize 重定向到错误的 URI 会引发无效的 URI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8421660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com