Skip to content
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ module.exports = function markdownLinkCheck(markdown, opts, callback) {
return;
}

let numCalls = 0;
linkCheck(link, opts, function (err, result) {
if (numCalls > 0) {
console.trace(`linkCheck called us back more than once for ${link}. This is likely due to a server answering HEAD with 302 and a body, against the HTTP spec. Ignoring.`);
return;
}
numCalls += 1;

if (opts.showProgressBar) {
bar.tick();
}
Expand Down
19 changes: 19 additions & 0 deletions test/markdown-link-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ describe('markdown-link-check', function () {
res.json({foo:'bar'});
});

app.use('/redirect-with-body-in-head', function (req, res) {
/* Don't judge me. I found at least one server on the
* Internet doing this and it triggered a bug. */
const body = 'Let me send you a body, although you only asked for a HEAD.';

const headers =
'HTTP/1.1 302 Found\r\n' +
'Connection: close\r\n' +
'Location: /foo/bar\r\n' +
`Content-Length: ${Buffer.byteLength(body)}\r\n` +
'\r\n';

res.socket.write(headers + body);
res.socket.destroy();
});

app.get('/basic-auth', function (req, res) {
if (req.headers["authorization"] === "Basic Zm9vOmJhcg==") {
res.sendStatus(200);
Expand Down Expand Up @@ -110,6 +126,9 @@ describe('markdown-link-check', function () {
expect(results).to.be.an('array');

const expected = [
// redirect-with-body-in-head
{ statusCode: 200, status: 'alive' },

// redirect-loop
{ statusCode: 0, status: 'dead' },

Expand Down
1 change: 1 addition & 0 deletions test/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This is a test file:

* [redirect-with-body-in-head](%%BASE_URL%%/redirect-with-body-in-head) (alive)
* [redirect-loop](%%BASE_URL%%/loop) (dead)
* [valid](%%BASE_URL%%/foo/bar) (alive)
* [invalid](%%BASE_URL%%/foo/dead) (dead)
Expand Down
Loading