w3c-validators/w3c_validators

Net::HTTPRetriableError: 302 "Found"

denisdefreyne opened this issue ยท 7 comments

The validator gem can fail withNet::HTTPRetriableError: 302 "Found".

Steps to reproduce

require 'w3c_validators'

File.write('lol.html', '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello</title></head><body><h1>Hi!</h1></body>')

::W3CValidators::MarkupValidator.new.validate_file('lol.html')

Error:

Net::HTTPRetriableError: 302 "Found"
	from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/net/http/response.rb:120:in `error!'
	from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/net/http/response.rb:129:in `value'
	from /usr/local/lib/ruby/gems/2.3.0/gems/w3c_validators-1.3/lib/w3c_validators/validator.rb:93:in `send_request'
	from /usr/local/lib/ruby/gems/2.3.0/gems/w3c_validators-1.3/lib/w3c_validators/validator.rb:90:in `send_request'
	from /usr/local/lib/ruby/gems/2.3.0/gems/w3c_validators-1.3/lib/w3c_validators/markup_validator.rb:131:in `validate'
	from /usr/local/lib/ruby/gems/2.3.0/gems/w3c_validators-1.3/lib/w3c_validators/markup_validator.rb:117:in `validate_file'
	from (irb):6
	from /usr/local/bin/irb:11:in `<main>'

Affected versions

  • w3c_validators 1.3
doc75 commented

Thanks for reporting this error.
It seems to be also present in v1.2.
I'll check if I can find a way to fix it, but it looks like the service output from w3.org has changed completely requiring an important rewrite.

doc75 commented

@ddfreyne I found out, that actually for the HTML 5 documents (starting with : ), the w3 checker is re-directing to the validator.w3.org/nu.

If you try (with master branch as there is an issue in v1.3) the following code, it will work:

require 'w3c_validators'

File.write('lol.html', '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello</title></hea><body><h1>Hi!    </h1></bo>')

res = ::W3CValidators::NuValidator.new.validate_file('lol.html')
puts res.inspect

I am still investigating how I can manage the redirect properly.

Hi there !

I don't know if this can be useful to you but, unless I'm totally misunderstanding, it looks like the MarkupValidator is using the https://validator.w3.org/check URL to validate documents and it looks like it is deprecated.

At least, it's not listed there.

Cheers!

doc75 commented

@robin850 You are right.
I do not want to break all existing users of this. One idea could be to drop it in a new major version (which can be non-backward compatible).

Readme file has a mention that the MarkupValidator should not be used.
It should probably be more clear.

Readme file has a mention that the MarkupValidator should not be used.

I really think that most people are just skimming rapidly README files, they just look for an example and don't actually read it unfortunately. ๐Ÿ˜• And to be honest, I didn't read it either. Once old code is set-up, you most-likely look at the documentation or issues tracker. Maybe you could display a deprecation warning instantiating a new MarkupValidator instance like:

The MarkupValidator class is deprecated as it cannot process HTML5 documents. Please prefer the NuValidator class instead.

doc75 commented

You are right, it will be more obvious with a deprecation warning.
I'll push this right away.

doc75 commented

Deprecation warning added with PR #34.
Next step is to publish a new major version removing this deprecated class.