Skip to content

Commit 2605d5a

Browse files
committed
Handle links with missing hrefs
1 parent b22d140 commit 2605d5a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/webmention.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ module.exports = function createWebmentionDispatcher(_log, db) {
5656
jobs = 0;
5757

5858
links.each(function(idx, el) {
59+
// XXX should we try to check for malformed URLs in a more generic way...?
60+
if (el.attribs.href.length === 0) {
61+
log.debug('Dropping attempt to send Webmention to empty href.');
62+
return;
63+
}
64+
5965
// XXX log `el` with a nice Bunyan formatter
6066
log.debug({target: el.attribs.href}, 'Attempting to send Webmention.');
6167
jobs++;

test/z-webmention-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var vows = require('perjury'),
5656
data = {
5757
singleLink: '<a href="http://nicenice.website/blag/new-puppy">So cute!</a>',
5858
multipleLinks: '<a href="http://magic.geek/pics/another-doggo">Even cuter!</a> I love <a href="http://catscatscats.org/">cats</a> too!',
59+
noHref: 'It\'s <a href="">yikes-worthy</a>!',
5960
noLinks: 'I have absolutely no links at all.'
6061
};
6162

@@ -185,6 +186,27 @@ vows.describe('Webmention module').addBatch({
185186
assert.equal(spy.callCount, 4);
186187
// XXX args
187188
},
189+
'and we call the module with a post that has a blank <a href="">': {
190+
topic: function(fns) {
191+
var webmention = fns[1],
192+
cb = this.callback;
193+
194+
webmention('http://malformed.technology/everything_is_terrible',
195+
200,
196+
data.noHref,
197+
function(err) {
198+
cb(err, fns);
199+
});
200+
},
201+
'it works': function(err) {
202+
assert.ifError(err);
203+
},
204+
'the spy wasn\'t called again': function(err, fns) {
205+
var spy = fns[0];
206+
assert.equal(spy.callCount, 4);
207+
// XXX args
208+
}
209+
},
188210
'and we call the module with a post that has no links at all': {
189211
topic: function(fns) {
190212
var webmention = fns[1],

0 commit comments

Comments
 (0)