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

Speed up the mailto check #174

Merged
merged 1 commit into from
Feb 20, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/html/proofer/checks/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def run
next
end

if link.scheme == 'mailto'
add_issue("#{link.href} contains no email address", l.line) if link.path.empty?
add_issue("#{link.href} contain an invalid email address", l.line) unless link.path.include?('@')
end

if link.scheme == 'tel'
case link.scheme
when 'mailto'
if link.path.empty?
add_issue("#{link.href} contains no email address", l.line)
elsif !link.path.include?('@')
add_issue("#{link.href} contains an invalid email address", l.line)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty mailtos can not include @.

end
when 'tel'
add_issue("#{link.href} contains no phone number", l.line) if link.path.empty?
end

Expand Down
9 changes: 9 additions & 0 deletions spec/html/proofer/fixtures/links/invalid_mailto_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>

<body>

<a href="mailto:octocat">Meow me</a>

</body>

</html>
6 changes: 6 additions & 0 deletions spec/html/proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
expect(proofer.failed_tests.first).to match(/mailto: contains no email address/)
end

it 'fails for invalid mailto links' do
invalidMailToLink = "#{FIXTURES_DIR}/links/invalid_mailto_link.html"
proofer = run_proofer(invalidMailToLink)
expect(proofer.failed_tests.first).to match(/mailto:octocat contains an invalid email address/)
end

it 'ignores valid tel links' do
ignorableLinks = "#{FIXTURES_DIR}/links/tel_link.html"
proofer = run_proofer(ignorableLinks)
Expand Down