diff --git a/Gemfile b/Gemfile index f7200f13..7f4f5e95 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -source 'http://rubygems.org' +source 'https://rubygems.org' gemspec diff --git a/README.md b/README.md index 00e20797..016cd78f 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Below is mostly comprehensive list of checks that HTMLProofer can perform. ### HTML -* Whether your HTML markup is valid. This is done via [Nokogiri](http://www.nokogiri.org/tutorials/ensuring_well_formed_markup.html) to ensure well-formed markup. +* Whether your HTML markup is valid. This is done via [Nokogumbo](https://github.com/rubys/nokogumbo) to validate well-formed HTML5 markup. ## Usage @@ -222,7 +222,7 @@ htmlproofer --assume-extension ./_site ### Using through Docker -If you have trouble with (or don't want to) install Ruby/Nokogiri, the command-line tool can be run through Docker. See [html-proofer-docker](https://github.com/18F/html-proofer-docker) for more information. +If you have trouble with (or don't want to) install Ruby/Nokogumbo, the command-line tool can be run through Docker. See [html-proofer-docker](https://github.com/18F/html-proofer-docker) for more information. ### Using as Rack middleware @@ -282,9 +282,10 @@ The `HTMLProofer` constructor takes an optional hash of additional options: | `check_external_hash` | Checks whether external hashes exist (even if the webpage exists). This slows the checker down. | `false` | | `check_favicon` | Enables the favicon checker. | `false` | | `check_opengraph` | Enables the Open Graph checker. | `false` | -| `check_html` | Enables HTML validation errors from Nokogiri | `false` | +| `check_html` | Enables HTML validation errors from Nokogumbo | `false` | | `check_img_http` | Fails an image if it's marked as `http` | `false` | -|`checks_to_ignore`| An array of Strings indicating which checks you'd like to not perform. | `[]` +| `check_sri` | Check that `` and `') + nokogiri = Nokogiri::HTML5('') checkable = HTMLProofer::Element.new(nokogiri.css('script').first, @check) expect(checkable.ignores_pattern_check([%r{\/assets\/.*(js|css|png|svg)}])).to eq true end it 'works for string patterns' do - nokogiri = Nokogiri::HTML('') + nokogiri = Nokogiri::HTML5('') checkable = HTMLProofer::Element.new(nokogiri.css('script').first, @check) expect(checkable.ignores_pattern_check(['/assets/main.js'])).to eq true end @@ -43,7 +43,7 @@ describe '#url' do it 'works for src attributes' do - nokogiri = Nokogiri::HTML('') + nokogiri = Nokogiri::HTML5('') checkable = HTMLProofer::Element.new(nokogiri.css('img').first, @check) expect(checkable.url).to eq 'image.png' end @@ -51,7 +51,7 @@ describe '#ignore' do it 'works for twitter cards' do - nokogiri = Nokogiri::HTML('') + nokogiri = Nokogiri::HTML5('') checkable = HTMLProofer::Element.new(nokogiri.css('meta').first, @check) expect(checkable.ignore?).to eq true end diff --git a/spec/html-proofer/fixtures/html/html5_tags.html b/spec/html-proofer/fixtures/html/html5_tags.html index 0ad4ae71..9b9af6ff 100644 --- a/spec/html-proofer/fixtures/html/html5_tags.html +++ b/spec/html-proofer/fixtures/html/html5_tags.html @@ -1,9 +1,9 @@ + - - -
-

Some text

-
- + + +
+

Some text

+
+ diff --git a/spec/html-proofer/fixtures/html/weird_onclick.html b/spec/html-proofer/fixtures/html/weird_onclick.html index 3ca33457..ee58f094 100644 --- a/spec/html-proofer/fixtures/html/weird_onclick.html +++ b/spec/html-proofer/fixtures/html/weird_onclick.html @@ -1 +1 @@ - + diff --git a/spec/html-proofer/html_spec.rb b/spec/html-proofer/html_spec.rb index d2c7dd07..76cbe909 100644 --- a/spec/html-proofer/html_spec.rb +++ b/spec/html-proofer/html_spec.rb @@ -21,40 +21,40 @@ expect(proofer.failed_tests).to eq [] end - it 'fails for an invalid tag' do + it 'works for custom tags' do html = "#{FIXTURES_DIR}/html/invalid_tag.html" proofer = run_proofer(html, :file, check_html: true, validation: { report_invalid_tags: true }) - expect(proofer.failed_tests.first).to match(/Tag myfancytag invalid \(line 2\)/) + expect(proofer.failed_tests).to eq [] end - it 'fails for an unmatched end tag' do + it 'allows an unmatched end tag' do html = "#{FIXTURES_DIR}/html/unmatched_end_tag.html" proofer = run_proofer(html, :file, check_html: true) - expect(proofer.failed_tests.first).to match(/Unexpected end tag : div \(line 3\)/) + expect(proofer.failed_tests).to eq [] end - it 'fails for an unescaped ampersand in attribute' do + it 'allows an unescaped ampersand in attribute' do html = "#{FIXTURES_DIR}/html/unescaped_ampersand_in_attribute.html" proofer = run_proofer(html, :file, check_html: true) - expect(proofer.failed_tests.first).to match(/htmlParseEntityRef: expecting ';' \(line 2\)/) + expect(proofer.failed_tests).to eq [] end - it 'fails for mismatch between opening and ending tag' do + it 'allows mismatch between opening and ending tag' do html = "#{FIXTURES_DIR}/html/opening_and_ending_tag_mismatch.html" proofer = run_proofer(html, :file, check_html: true) - expect(proofer.failed_tests.first).to match(/Opening and ending tag mismatch: p and strong/) + expect(proofer.failed_tests).to eq [] end - it 'fails for div inside head' do + it 'allows div inside head' do html = "#{FIXTURES_DIR}/html/div_inside_head.html" proofer = run_proofer(html, :file, check_html: true) - expect(proofer.failed_tests.first).to match(/Unexpected end tag : head \(line 5\)/) + expect(proofer.failed_tests).to eq [] end - it 'fails for missing closing quotation mark in href' do + it 'allows missing closing quotation mark in href' do html = "#{FIXTURES_DIR}/html/missing_closing_quotes.html" proofer = run_proofer(html, :file, check_html: true) - expect(proofer.failed_tests.to_s).to match(/Couldn't find end of Start Tag a \(line 6\)/) + expect(proofer.failed_tests).to eq [] end it "doesn't fail for single ampersand" do @@ -63,10 +63,10 @@ expect(proofer.failed_tests).to eq [] end - it 'fails for single ampersand when asked' do + it 'allows single ampersand' do html = "#{FIXTURES_DIR}/html/single_amp.html" proofer = run_proofer(html, :file, check_html: true, validation: { report_missing_names: true }) - expect(proofer.failed_tests.first).to match('htmlParseEntityRef: no name') + expect(proofer.failed_tests).to eq [] end it 'ignores embeded scripts when asked' do @@ -80,7 +80,7 @@ opts = { check_html: true, validation: { report_script_embeds: true } } ignorable_script = "#{FIXTURES_DIR}/html/ignore_script_embeds.html" proofer = run_proofer(ignorable_script, :file, opts) - expect(proofer.failed_tests.length).to eq 2 + expect(proofer.failed_tests).to eq [] end it 'does not fail for weird iframe sources' do diff --git a/spec/html-proofer/links_spec.rb b/spec/html-proofer/links_spec.rb index aa786fe0..e67dbf81 100644 --- a/spec/html-proofer/links_spec.rb +++ b/spec/html-proofer/links_spec.rb @@ -97,10 +97,10 @@ expect(proofer.failed_tests).to eq [] end - it 'fails for link with no href' do + it 'allows link with no href' do missing_link_href_filepath = "#{FIXTURES_DIR}/links/missing_link_href.html" proofer = run_proofer(missing_link_href_filepath, :file) - expect(proofer.failed_tests.first).to match(/anchor has no href attribute/) + expect(proofer.failed_tests).to eq [] end it 'should follow redirects' do @@ -247,16 +247,16 @@ expect(proofer.failed_tests).to eq [] end - it 'fails for empty href within link elements' do + it 'allows empty href on link elements' do head_link = "#{FIXTURES_DIR}/links/head_link_href_empty.html" proofer = run_proofer(head_link, :file) - expect(proofer.failed_tests.first).to match(/anchor has no href attribute/) + expect(proofer.failed_tests).to eq [] end - it 'fails for absent href within link elements' do + it 'allows missing href on link elements' do head_link = "#{FIXTURES_DIR}/links/head_link_href_absent.html" proofer = run_proofer(head_link, :file) - expect(proofer.failed_tests.first).to match(/anchor has no href attribute/) + expect(proofer.failed_tests).to eq [] end it 'fails for internal linking to a directory without trailing slash' do @@ -366,10 +366,10 @@ expect(proofer.failed_tests).to eq [] end - it 'fails for placeholder with empty id' do + it 'allows placeholder with empty id' do empty_id = "#{FIXTURES_DIR}/links/placeholder_with_empty_id.html" proofer = run_proofer(empty_id, :file) - expect(proofer.failed_tests.first).to match(/anchor has no href attribute/) + expect(proofer.failed_tests).to eq [] end it 'ignores non-http(s) protocols' do @@ -525,7 +525,7 @@ missing_href = "#{FIXTURES_DIR}/links/blank_href_htmlunknown.html" proofer = run_proofer(missing_href, :file) - expect(proofer.failed_tests.length).to eq 1 + expect(proofer.failed_tests).to eq [] end it 'can skip expecting href for anchors in non-HTML5' do diff --git a/spec/html-proofer/scripts_spec.rb b/spec/html-proofer/scripts_spec.rb index 8675894e..563c02da 100644 --- a/spec/html-proofer/scripts_spec.rb +++ b/spec/html-proofer/scripts_spec.rb @@ -18,7 +18,8 @@ it 'fails for missing internal src' do file = "#{FIXTURES_DIR}/scripts/script_missing_internal.html" proofer = run_proofer(file, :file) - expect(proofer.failed_tests.first).to match(/doesnotexist.js does not exist \(line 5\)/) + expect(proofer.failed_tests.length).to eq 1 + expect(proofer.failed_tests.first).to include('spec/html-proofer/fixtures/scripts/script_missing_internal.html: internal script doesnotexist.js does not exist (line 5)') end it 'works for present content' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f9fcf900..dd63e917 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,7 +34,7 @@ def capture_stderr(*) $stdout = StringIO.new unless ENV['VERBOSE'] begin yield - rescue RuntimeError # rubocop:disable Lint/HandleExceptions + rescue RuntimeError # rubocop:disable Lint/SuppressedException ensure $stderr = original_stderr $stdout = original_stdout unless ENV['VERBOSE']