Skip to content

Commit

Permalink
Merge pull request #657 from PeterJCLaw/mailto-without-email-ignore
Browse files Browse the repository at this point in the history
Add flag to allow no-email mailto links
  • Loading branch information
gjtorikian authored Oct 19, 2021
2 parents e6b1f2e + 103f26c commit 2d924a1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ The `HTMLProofer` constructor takes an optional hash of additional options:
| `http_status_ignore` | An array of numbers representing status codes to ignore. | `[]`
| `internal_domains`| An array of Strings containing domains that will be treated as internal urls. | `[]` |
| `log_level` | Sets the logging level, as determined by [Yell](https://github.com/rudionrails/yell). One of `:debug`, `:info`, `:warn`, `:error`, or `:fatal`. | `:info`
| `ignore_empty_mailto` | If `true`, allows `mailto:` `href`s which do not contain an email address. | `false`
| `only_4xx` | Only reports errors for links that fall within the 4xx status code range. | `false` |
| `root_dir` | The absolute path to the directory serving your html-files. | "" |
| `typhoeus_config` | A JSON-formatted string. Parsed using `JSON.parse` and mapped on top of the default configuration values so that they can be overridden. | `{}` |
Expand Down
1 change: 1 addition & 0 deletions bin/htmlproofer
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Mercenary.program(:htmlproofer) do |p|
p.option 'file_ignore', '--file-ignore file1,[file2,...]', Array, 'A comma-separated list of Strings or RegExps containing file paths that are safe to ignore'
p.option 'http_status_ignore', '--http-status-ignore 123,[xxx, ...]', Array, 'A comma-separated list of numbers representing status codes to ignore.'
p.option 'internal_domains', '--internal-domains domain1,[domain2,...]', Array, 'A comma-separated list of Strings containing domains that will be treated as internal urls.'
p.option 'ignore_empty_mailto', '--ignore-empty-mailto', 'If `true`, allows `mailto:` `href`s which do not contain an email address'
p.option 'report_invalid_tags', '--report-invalid-tags', 'When `check_html` is enabled, HTML markup that is unknown to Nokogumbo are reported as errors (default: `false`)'
p.option 'report_missing_names', '--report-missing-names', 'When `check_html` is enabled, HTML markup that are missing entity names are reported as errors (default: `false`)'
p.option 'report_script_embeds', '--report-script-embeds', 'When `check_html` is enabled, `script` tags containing markup are reported as errors (default: `false`)'
Expand Down
2 changes: 1 addition & 1 deletion lib/html-proofer/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def time_ago(measurement, unit)
when :months
@cache_datetime >> -measurement
when :weeks
@cache_datetime - measurement * 7
@cache_datetime - (measurement * 7)
when :days
@cache_datetime - measurement
when :hours
Expand Down
2 changes: 1 addition & 1 deletion lib/html-proofer/check/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def check_schemes(link, line, content)

def handle_mailto(link, line, content)
if link.path.empty?
add_issue("#{link.href} contains no email address", line: line, content: content)
add_issue("#{link.href} contains no email address", line: line, content: content) unless link.ignore_empty_mailto?
elsif !link.path.include?('@')
add_issue("#{link.href} contains an invalid email address", line: line, content: content)
end
Expand Down
1 change: 1 addition & 0 deletions lib/html-proofer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Configuration
http_status_ignore: [],
internal_domains: [],
log_level: :info,
ignore_empty_mailto: false,
only_4xx: false,
url_ignore: [],
url_swap: {}
Expand Down
4 changes: 4 additions & 0 deletions lib/html-proofer/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def check_sri?
@check.options[:check_sri]
end

def ignore_empty_mailto?
@check.options[:ignore_empty_mailto]
end

# path is external to the file
def external?
!internal?
Expand Down
6 changes: 6 additions & 0 deletions spec/html-proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@
expect(proofer.failed_tests).to eq []
end

it 'ignores blank mailto links when configured to allow them' do
blank_mail_to_link = "#{FIXTURES_DIR}/links/blank_mailto_link.html"
proofer = run_proofer(blank_mail_to_link, :file, ignore_empty_mailto: true)
expect(proofer.failed_tests).to eq []
end

it 'fails for blank mailto links' do
blank_mail_to_link = "#{FIXTURES_DIR}/links/blank_mailto_link.html"
proofer = run_proofer(blank_mail_to_link, :file)
Expand Down

0 comments on commit 2d924a1

Please sign in to comment.