Skip to content

Commit

Permalink
Merge pull request #622 from gjtorikian/fix-middleware-url-ignore
Browse files Browse the repository at this point in the history
Correct link ignore regexp
  • Loading branch information
gjtorikian committed Feb 21, 2021
2 parents 3bb8d35 + 777d834 commit 98554c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/html-proofer/element.rb
Expand Up @@ -220,6 +220,8 @@ def absolute_path
end

def ignores_pattern_check(links)
return false unless links.is_a?(Array)

links.each do |ignore|
case ignore
when String
Expand Down
2 changes: 1 addition & 1 deletion lib/html-proofer/middleware.rb
Expand Up @@ -22,7 +22,7 @@ def self.options
allow_hash_href: true,
check_external_hash: true,
check_html: true,
url_ignore: [/.*/], # Don't try to check if local files exist
url_ignore: [%r{^/}], # Don't try to check if local files exist
validation: { report_eof_tags: true }
}
end
Expand Down
40 changes: 40 additions & 0 deletions spec/html-proofer/middleware_spec.rb
Expand Up @@ -32,6 +32,46 @@
end
end

context 'options' do
let(:response_fixture) { File.join(File.absolute_path(FIXTURES_DIR), 'links', 'broken_root_link_internal.html') }

before(:each) do
@default_opts = HTMLProofer::Middleware.options[:url_ignore]
end

after(:each) do
HTMLProofer::Middleware.options[:url_ignore] = @default_opts
end

let(:middleware_with_ignore) do
HTMLProofer::Middleware.options[:url_ignore] = [/broken/]
HTMLProofer::Middleware.new(app)
end
let(:middleware_with_no_ignore) do
HTMLProofer::Middleware.options[:url_ignore] = nil
HTMLProofer::Middleware.new(app)
end

let(:subject) { middleware.call(request) }
let(:subject_with_ignore) { middleware_with_ignore.call(request) }
let(:subject_with_no_ignore) { middleware_with_no_ignore.call(request) }
context 'internal files' do
it 'does not raise an error with default options set' do
subject
end

it 'does not raise an error with options explicitly set' do
subject_with_ignore
end

it 'does raise an error with options removed' do
expect do
subject_with_no_ignore
end.to raise_error(HTMLProofer::Middleware::InvalidHtmlError)
end
end
end

context 'proofer-ignore' do
let(:skip_request) { { 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => 'proofer-ignore' } }
let(:subject) { middleware.call(skip_request) }
Expand Down

0 comments on commit 98554c8

Please sign in to comment.