diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82d85d34..1ba668e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,13 +20,13 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install libxslt and libxml2 + run: sudo apt-get install libxslt-dev libxml2-dev - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} # bundler-cache: true - - name: Install libxslt and libxml2 - run: sudo apt-get install libxslt-dev libxml2-dev - name: Install dependencies run: bundle install - name: Run tests diff --git a/.rubocop.yml b/.rubocop.yml index cab6b95a..8437a0c5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,17 +1,3 @@ -AllCops: - Exclude: - - "vendor/**/*" - inherit_gem: rubocop-standard: - config/default.yml - -Style/StringLiterals: - Enabled: true - EnforcedStyle: single_quotes - -Naming/FileName: - Enabled: false - -Style/Documentation: - Enabled: false diff --git a/lib/html-proofer.rb b/lib/html-proofer.rb index d828b453..bd3711d1 100644 --- a/lib/html-proofer.rb +++ b/lib/html-proofer.rb @@ -1,3 +1,4 @@ +# rubocop:disable Naming/FileName # frozen_string_literal: true def require_all(path) @@ -52,3 +53,4 @@ def self.check_links(links, options = {}) HTMLProofer::Runner.new(links, options) end end +# rubocop:enable Naming/FileName diff --git a/lib/html-proofer/runner.rb b/lib/html-proofer/runner.rb index d37523c7..e853ac3c 100644 --- a/lib/html-proofer/runner.rb +++ b/lib/html-proofer/runner.rb @@ -214,7 +214,8 @@ def print_failed_tests sorted_failures.sort_and_report count = @failures.length failure_text = pluralize(count, 'failure', 'failures') - raise @logger.colorize :fatal, "HTML-Proofer found #{failure_text}!" + @logger.log :fatal, "\nHTML-Proofer found #{failure_text}!" + exit 1 end # Set before_request callback. diff --git a/lib/html-proofer/url_validator.rb b/lib/html-proofer/url_validator.rb index a07a8c3e..4cf85c11 100644 --- a/lib/html-proofer/url_validator.rb +++ b/lib/html-proofer/url_validator.rb @@ -120,7 +120,7 @@ def establish_queue(external_urls) def clean_url(href) # catch any obvious issues, like strings in port numbers parsed = Addressable::URI.parse(href) - if href =~ /^([!#{$&}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/ + if href =~ /^([!#{Regexp.last_match(0)}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/ href else parsed.normalize diff --git a/spec/html-proofer/fixtures/links/hash/inner.html b/spec/html-proofer/fixtures/links/hash/inner.html new file mode 100644 index 00000000..8f49f052 --- /dev/null +++ b/spec/html-proofer/fixtures/links/hash/inner.html @@ -0,0 +1,7 @@ +English below + +
+
+ +

English

+ diff --git a/spec/html-proofer/proofer_spec.rb b/spec/html-proofer/proofer_spec.rb index bfc4ec52..359aa0ab 100644 --- a/spec/html-proofer/proofer_spec.rb +++ b/spec/html-proofer/proofer_spec.rb @@ -57,6 +57,8 @@ Tel me - spec/html-proofer/fixtures/sorting/path/single_issue.html * image has a terrible filename (./Screen Shot 2012-08-09 at 7.51.18 AM.png) (line 1) + +HTML-Proofer found 4 failures! '.strip) end @@ -71,6 +73,8 @@ * spec/html-proofer/fixtures/sorting/issue/broken_image_two.html (line 1) - internal image NOT_AN_IMAGE does not exist * spec/html-proofer/fixtures/sorting/issue/broken_image_two.html (line 4) + +HTML-Proofer found 5 failures! '.strip) end @@ -82,7 +86,8 @@ - 301 * spec/html-proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed: 301 * spec/html-proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed: 301 - '.strip) +HTML-Proofer found 3 failures! + '.strip) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2710ee44..9a31b9ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'vcr' require 'timecop' require_relative '../lib/html-proofer' +require 'open3' FIXTURES_DIR = 'spec/html-proofer/fixtures' @@ -28,7 +29,7 @@ def capture_stderr(*) $stdout = StringIO.new unless ENV['VERBOSE'] begin yield - rescue RuntimeError # rubocop:disable Lint/SuppressedException + rescue SystemExit # rubocop:disable Lint/SuppressedException ensure $stderr = original_stderr $stdout = original_stdout unless ENV['VERBOSE'] @@ -68,7 +69,8 @@ def send_proofer_output(file, type, opts = {}) end def make_bin(cmd, path = nil) - `bin/htmlproofer #{cmd} #{path}` + stdout, stderr = Open3.capture3("bin/htmlproofer #{cmd} #{path}") + "#{stdout}\n#{stderr}" end def make_cassette_name(file, opts)