Skip to content

Commit

Permalink
Handle links with missing hrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
strugee committed Dec 29, 2017
1 parent b22d140 commit 2605d5a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/webmention.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ module.exports = function createWebmentionDispatcher(_log, db) {
jobs = 0;

links.each(function(idx, el) {
// XXX should we try to check for malformed URLs in a more generic way...?
if (el.attribs.href.length === 0) {
log.debug('Dropping attempt to send Webmention to empty href.');
return;
}

// XXX log `el` with a nice Bunyan formatter
log.debug({target: el.attribs.href}, 'Attempting to send Webmention.');
jobs++;
Expand Down
22 changes: 22 additions & 0 deletions test/z-webmention-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var vows = require('perjury'),
data = {
singleLink: '<a href="http://nicenice.website/blag/new-puppy">So cute!</a>',
multipleLinks: '<a href="http://magic.geek/pics/another-doggo">Even cuter!</a> I love <a href="http://catscatscats.org/">cats</a> too!',
noHref: 'It\'s <a href="">yikes-worthy</a>!',
noLinks: 'I have absolutely no links at all.'
};

Expand Down Expand Up @@ -185,6 +186,27 @@ vows.describe('Webmention module').addBatch({
assert.equal(spy.callCount, 4);
// XXX args
},
'and we call the module with a post that has a blank <a href="">': {
topic: function(fns) {
var webmention = fns[1],
cb = this.callback;

webmention('http://malformed.technology/everything_is_terrible',
200,
data.noHref,
function(err) {
cb(err, fns);
});
},
'it works': function(err) {
assert.ifError(err);
},
'the spy wasn\'t called again': function(err, fns) {
var spy = fns[0];
assert.equal(spy.callCount, 4);
// XXX args
}
},
'and we call the module with a post that has no links at all': {
topic: function(fns) {
var webmention = fns[1],
Expand Down

0 comments on commit 2605d5a

Please sign in to comment.