Giter Site home page Giter Site logo

w3c_validators's People

Contributors

alexdunae avatar benkoshy avatar der-flo avatar doc75 avatar jaimeiniesta avatar kamipo avatar koic avatar mkb avatar roberthopman avatar romanbsd avatar spk avatar takaltoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

w3c_validators's Issues

Offline mode ?

This gem uses the online W3C validator. That's great! But:

  1. It raises some privacy concerns (maybe you don't want to send your document to W3C)
  2. It's slow (you need to wait after the network and W3C's servers if they are busy)
  3. It doesn't work if you're offline

How about using the offline version of the same tool?

Internal server error on validating CSS

I cannot validate any CSS. The following code:

require 'w3c_validators'

include W3CValidators

@validator = CSSValidator.new

results = @validator.validate_uri('http://www.csszengarden.com/examples/style.css')

if results.errors.length > 0
    results.errors.each do |err|
          puts err.to_s
            end
else
    puts 'Valid!'
end

results in the following error:

/Users/me/.rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http/response.rb:120:in `error!': 500"Internal Server Error" (Net::HTTPFatalError)
        from /Users/me/.rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http/response.rb:129:in `value'
        from /Users/me/.gem/ruby/2.3.1/gems/w3c_validators-1.2/lib/w3c_validators/validator.rb:88:in `send_request'
        from /Users/me/.gem/ruby/2.3.1/gems/w3c_validators-1.2/lib/w3c_validators/css_validator.rb:87:in `validate'
        from /Users/me/.gem/ruby/2.3.1/gems/w3c_validators-1.2/lib/w3c_validators/css_validator.rb:58:in `validate_uri'
        from validate.rb:7:in `<main>'

constant Net::HTTPServerException is deprecated

Currently, the W3C validation service seems to be down (error 503 when trying to validate a page using the web form or the gem). Hence, the gem cannot validate any page (which is okay).

However, this also uncovered use of a deprecated constant:

…/lib/w3c_validators/validator.rb:177: warning: constant Net::HTTPServerException is deprecated

Incorrect handling of HTTP redirect responses

The feed validator class is failing to properly validate RSS files due to the W3C website dropping support for HTTP requests:

FEED_VALIDATOR_URI = 'http://validator.w3.org/feed/check.cgi'

POSTing any kind of data to http://validator.w3.org/feed/check.cgi results in a 301 Moved Permanently (even when sending a valid RSS feed file):

~ cat sample_feed.rss 
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<channel>
  <title>W3Schools Home Page</title>
  <link>https://www.w3schools.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>https://www.w3schools.com/xml/xml_rss.asp</link>
    <description>New RSS tutorial on W3Schools</description>
  </item>
  <item>
    <title>XML Tutorial</title>
    <link>https://www.w3schools.com/xml</link>
    <description>New XML tutorial on W3Schools</description>
  </item>
</channel>

</rss>~ gem list w3c     

*** LOCAL GEMS ***

w3c_validators (1.3.6)~ irb
irb(main):001:0> require 'w3c_validators'
=> true
irb(main):002:0> v = W3CValidators::FeedValidator.new
=> #<W3CValidators::FeedValidator:0x000055c69221b598 @validator_uri=#<URI::HTTP http://validator.w3.org/feed/check.cgi>, @options={:proxy_host=>nil, :proxy_po...
irb(main):003:0> v.validate_file("sample_feed.rss")
Traceback (most recent call last):
       11: from /usr/bin/irb:23:in `<main>'
       10: from /usr/bin/irb:23:in `load'
        9: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        8: from (irb):3
        7: from /var/lib/gems/2.7.0/gems/w3c_validators-1.3.6/lib/w3c_validators/feed_validator.rb:48:in `validate_file'
        6: from /var/lib/gems/2.7.0/gems/w3c_validators-1.3.6/lib/w3c_validators/feed_validator.rb:33:in `validate_text'
        5: from /var/lib/gems/2.7.0/gems/w3c_validators-1.3.6/lib/w3c_validators/feed_validator.rb:59:in `validate'
        4: from /var/lib/gems/2.7.0/gems/w3c_validators-1.3.6/lib/w3c_validators/validator.rb:110:in `send_request'
        3: from /var/lib/gems/2.7.0/gems/w3c_validators-1.3.6/lib/w3c_validators/validator.rb:113:in `send_request'
        2: from /usr/lib/ruby/2.7.0/net/http/response.rb:133:in `value'
        1: from /usr/lib/ruby/2.7.0/net/http/response.rb:124:in `error!'
Net::HTTPRetriableError (301 "Moved Permanently")

Upon further inspection, it became clear that the method send_request is at fault:

  • options[:url] = response['location']
    • options[:url] containing the new URI is never used by the following call to send_request: it only uses @validator_uri, which still contains the old URI subject to redirection. A simple fix would be to replace this line by something like @validator_uri = URI.parse(response['location']) to update the instance variable.

I also noticed a probably poorly named variable:

  • if response.kind_of?(Net::HTTPRedirection) and response['location'] and not following_redirect
    • Semantics would have that not following_redirect become just following_redirect to actually follow redirects. The default boolean value used in the method signature would also need to become true to default to following redirects, if that is the desired behaviour.

Truncated error messages on 1.1.1

While on 1.0.2 it works fine, now with 1.1.1 I can't see the full error messages, they get truncated. For example:

MarkupValidator.new.validate_uri('http://ryanair.com').errors.first.to_s

this will output on 1.1.1:

"ERROR; URI: http://www.ryanair.com/en; line " 

while on 1.0.2 it will be fine:

"ERROR; URI: http://www.ryanair.com/en; line 98: general entity \"Bs\" not defined and no default entity"

I've tried this on ruby 1.8.6 and ruby 1.9.2, same results.

Thanks!

Switch from json to json_pure

What was previously known as json, a gem used here, is now called json_pure.

And the json gem was changed be a high-performance binary module.

Don't we want high performance? Well we don't use a ton of JSON processing here, so switching to the json_pure package will be easier for people to use. For example, as current w3c_validators cannot be used on Apple+DevContainers platforms, discussed at rubygems/rubygems#6212

validator#validate_text raises W3CValidators::ValidatorUnavailable

Caused by the API returning HTTP 400 Bad Request. Calling #validate_uri makes a successful request.

W3CValidators::ValidatorUnavailable: unable to connect to the validator at https://validator.w3.org/nu/ (response was 400 "Bad request").
from ~/.gem/ruby/2.4.1/gems/w3c_validators-1.3.3/lib/w3c_validators/validator.rb:116:in `rescue in send_request'
from ~/.gem/ruby/2.4.1/gems/w3c_validators-1.3.3/lib/w3c_validators/validator.rb:43:in `send_request'
from ~/.gem/ruby/2.4.1/gems/w3c_validators-1.3.3/lib/w3c_validators/nu_validator.rb:68:in `validate'
from ~/.gem/ruby/2.4.1/gems/w3c_validators-1.3.3/lib/w3c_validators/nu_validator.rb:34:in `validate_uri'

Net::HTTPRetriableError: 302 "Found"

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

README document uses :proxy_server instead of :proxy_host

Hi Alex,

Just found a small error in your README document.

The document gives the proxy example as:

validator = MarkupValidator.new(:proxy_server => 'proxy.example.com',
                            :proxy_port   => 80,
                            :proxy_user   => 'optional',
                            :proxy_pass   => 'optional')

Whereas looking at the code this should be "proxy_host" instead of "proxy_server":

validator = MarkupValidator.new(:proxy_host => 'proxy.example.com',
                            :proxy_port   => 80,
                            :proxy_user   => 'optional',
                            :proxy_pass   => 'optional')

Incompatible with Rails 4.2

Trying to update to Rails 4.2 while using w3c_validators results in this error:

Bundler could not find compatible versions for gem "nokogiri":
  In Gemfile:
    rails (~> 4.2.0) ruby depends on
      actionpack (= 4.2.0) ruby depends on
        rails-dom-testing (>= 1.0.5, ~> 1.0) ruby depends on
          nokogiri (~> 1.6.0) ruby

    w3c_validators (= 1.2) ruby depends on
      nokogiri (1.5.11)

Ruby 1.9.2?

Seems not to work with 1.9.2? I'm using via Nanoc. Ok with 1.8.6:

rake aborted!
502 "Proxy Error"
V:/x/Ruby-192-p0/lib/ruby/1.9.1/net/http.rb:2295:in error!' V:/x/Ruby-192-p0/lib/ruby/1.9.1/net/http.rb:2304:invalue'
V:/x/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/alexdunae-w3c_validators-1.0.0/lib/w3c_validators/validator.rb:57:in send_request' V:/x/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/alexdunae-w3c_validators-1.0.0/lib/w3c_validators/markup_validator.rb:129:invalidate'
V:/x/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/alexdunae-w3c_validators-1.0.0/lib/w3c_validators/markup_validator.rb:115:in `validate_file'

NuValidator raising ParsingError, service returning HTML instead of JSON?

I'm getting a W3CValidators::ParsingError: unable to parse the response from the validator. when trying to use the NuValidator like so:

validator = ::W3CValidators::NuValidator.new
results = validator.validate_file(file)

file being a temp file containing HTML5 markup. I also tried validate_text, but got the very same error.

Details of ParsingError raised:

 # --- Caused by: ---
     # JSON::ParserError:
     #   757: unexpected token at '<!DOCTYPE html>
     #   <html lang="en"><head><link href="icon.png" rel="icon"><link href="style.css" rel="stylesheet"><title>(X)HTML5 validation results</title></head><body><h1>(X)HTML5 validation results</h1><form method="get" class="simple">....

I already checked the request sent to validator.nu, which contains the out=json parameter, so should be fine. Any idea what's wrong with the service?

Thanks so much for providing this awesome gem, btw. Looking forward to get this to work properly soon :)

NuValidator timeout

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.

Next release?

Looks like it has been a while since the last release. There have been a couple important bug fixes since 1.1.1 -- is there any chance that you can push a new release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.