Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct link ignore regexp #622

Merged
merged 1 commit into from Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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