w3c-validators/w3c_validators

NuValidator timeout

denisdefreyne opened this issue · 7 comments

Steps to reproduce

W3CValidators::NuValidator.new.validate_text('<html>')

Expected result

Regular output.

Actual result

Net::OpenTimeout: execution expired
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `initialize'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `open'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `block in connect'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/timeout.rb:103:in `timeout'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:902:in `connect'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:876:in `start'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:1407:in `request'
	from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/net/http.rb:1361:in `request_post'
	from /usr/local/lib/ruby/gems/2.4.0/gems/w3c_validators-1.3.2/lib/w3c_validators/validator.rb:102:in `send_request'
	from /usr/local/lib/ruby/gems/2.4.0/gems/w3c_validators-1.3.2/lib/w3c_validators/nu_validator.rb:72:in `validate'
	from /usr/local/lib/ruby/gems/2.4.0/gems/w3c_validators-1.3.2/lib/w3c_validators/nu_validator.rb:42:in `validate_text'
	from (irb):2
	from /usr/local/bin/irb:11:in `<main>'

Notes

  • MarkupValidator works fine.
doc75 commented

I tried your example:

require 'w3c_validators'

res = W3CValidators::NuValidator.new.validate_text('<html>')
puts res.inspect

The output is:

#<W3CValidators::Results:0x00000002a4f860 @messages=[#<W3CValidators::Message:0x00000002a4ec80 @type=:error, @uri=nil, @line=1, @col=1, @source="<html>", @explanation=nil, @message="Start tag seen without seeing a doctype first. Expected e.g. “<!DOCTYPE html>”.", @message_id=nil, @message_count=nil, @element=nil, @parent=nil, @value=nil, @level=nil>, #<W3CValidators::Message:0x00000002a4e708 @type=:error, @uri=nil, @line=1, @col=1, @source="<html>", @explanation=nil, @message="Element “head” is missing a required instance of child element “title”.", @message_id=nil, @message_count=nil, @element=nil, @parent=nil, @value=nil, @level=nil>], @uri=nil, @checked_by="https://validator.nu/", @doctype=:html5, @css_level=nil, @charset="UTF-8", @validity=false, @debug_messages={}>

So it seems to work on my side.
I do not know what could cause the timeou for you.
I remember that Markup check has a ban system, but I have not seen it for the Nu Validator.

Can you from the same machine perform the online check in your brower at https://validator.nu/ ?

Troubling… it works from the browser, but the command line times out. How would I reproduce this with curl? (Having trouble figuring out right now.)

doc75 commented

You can try this:

curl -X POST -H 'Content-Type: text/html; charset=utf-8' -H 'Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3' -H 'Accept: */*' -H 'User-Agent: Ruby' -d "<html>" "https://validator.nu/?out=json&parser=html&showsource=yes"

Ii outputs this for me:

{"messages":[{"type":"error","lastLine":1,"lastColumn":6,"firstColumn":1,"message":"Start tag seen without seeing a doctype first. Expected e.g. “<!DOCTYPE html>”.","extract":"<html>","hiliteStart":0,"hiliteLength":6},{"type":"error","lastLine":1,"lastColumn":6,"firstColumn":1,"message":"Element “head” is missing a required instance of child element “title”.","extract":"<html>","hiliteStart":0,"hiliteLength":6}],"source":{"type":"text/html","encoding":"UTF-8","code":"<html>"}}

That curl command works for me, and gives the same output as yours.

I can reproduce the problem with net/http:

http = Net::HTTP.new('validator.nu', 443)
http.use_ssl = true
http.post2('/?out=json&parser=html&showsource=yes', '<html>', {})
# … timeout …

It seems like there are a few HTTPS URL that are causing issues with net/http, and so this might not be a w3c-validator issue:

Net::HTTP.get(URI('https://encrypted.google.com'))
# … timeout …

yet:

Net::HTTP.get(URI('https://github.com')).size
=> 92727

I am using Ruby 2.4:

ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
doc75 commented

Thanks for the explanation.
Seems specific to some environment.
I am on the same ruby version (2.4.0p0) but on Linux, and I have never faced this issue.