Skip to content

Commit

Permalink
support mailto: with RFC6068 hfields
Browse files Browse the repository at this point in the history
  • Loading branch information
tcort committed Jun 2, 2018
1 parent a247c2f commit e412138
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/proto/mailto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const LinkCheckResult = require('../LinkCheckResult');

module.exports = {
check: function (link, opts, callback) {
callback(null, new LinkCheckResult(opts, link, Isemail.validate(link.substr(7)) ? 200 : 400, null));
const address = link
.substr(7) // strip "mailto:"
.split('?')[0]; // trim ?subject=blah hfields

/* per RFC6068, the '?' is a reserved delimiter and email addresses containing '?' must be encoded,
* so it's safe to split on '?' and pick [0].
*/

callback(null, new LinkCheckResult(opts, link, Isemail.validate(address) ? 200 : 400, null));
}
};
18 changes: 18 additions & 0 deletions test/link-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ describe('link-check', function () {
});
});

it('should handle valid mailto with encoded characters in address', function (done) {
linkCheck('mailto:foo%[email protected]', function (err, result) {
expect(err).to.be(null);
expect(result.link).to.be('mailto:foo%[email protected]');
expect(result.status).to.be('alive');
done();
});
});

it('should handle valid mailto containing hfields', function (done) {
linkCheck('mailto:[email protected]?subject=caf%C3%A9', function (err, result) {
expect(err).to.be(null);
expect(result.link).to.be('mailto:[email protected]?subject=caf%C3%A9');
expect(result.status).to.be('alive');
done();
});
});

it('should handle invalid mailto', function (done) {
linkCheck('mailto:foo@@bar@@baz', function (err, result) {
expect(err).to.be(null);
Expand Down

0 comments on commit e412138

Please sign in to comment.