Skip to content

Commit

Permalink
fix: don't try to parse non-text
Browse files Browse the repository at this point in the history
wm was trying to DOM parse an mp3 file which would blow up

Fixes #24
  • Loading branch information
remy committed May 3, 2020
1 parent 37e3bba commit 73dfb61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ function getWebmentionUrl(opts, callback) {
return;
}
}

// don't try to parse non-text (i.e. mp3s!)
if (!res.headers['content-type'].startsWith('text/')) {
callback();
return;
}
var buf = '';

res.on('data', chunk => (buf += chunk));
res.on('data', chunk => (buf += chunk.toString()));
res.on('end', () => {
callback(null, findEndpoints(buf.toString(), res.responseUrl));
});
Expand Down
1 change: 1 addition & 0 deletions lib/ignored-endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ e.g. .github.com will match both github.com and gist.github.com

module.exports = `
.amazon.com
.amazonaws.com
.cloudfront.net
.facebook.com
.flickr.com
Expand Down

0 comments on commit 73dfb61

Please sign in to comment.