diff --git a/lib/index.js b/lib/index.js index f081c93..ada95cc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -169,7 +169,11 @@ async function rule(tree, file, options) { product.fatal = message.fatal } - if (result.status === 'alive' && new URL(url).href !== result.url) { + if ( + result.permanent && + result.status === 'alive' && + new URL(url).href !== result.url + ) { const message = file.message( 'Unexpected redirecting URL `' + url + diff --git a/test.js b/test.js index a5dc4bd..931c9ff 100644 --- a/test.js +++ b/test.js @@ -327,7 +327,7 @@ No URLs in here. assert.deepEqual(file.messages.map(String), []) }) - await t.test('should support redirects', async function () { + await t.test('should support permanent redirects', async function () { const globalDispatcher = getGlobalDispatcher() const mockAgent = new MockAgent() mockAgent.enableNetConnect(/(?=a)b/) @@ -354,4 +354,30 @@ No URLs in here. '1:1-1:30: Unexpected redirecting URL `https://example.com/from`, expected final URL `https://example.com/to`' ]) }) + + await t.test('should support temporary redirects', async function () { + const globalDispatcher = getGlobalDispatcher() + const mockAgent = new MockAgent() + mockAgent.enableNetConnect(/(?=a)b/) + setGlobalDispatcher(mockAgent) + const site = mockAgent.get('https://example.com') + + site.intercept({path: '/from'}).reply(302, '', { + headers: {Location: '/to'} + }) + + site.intercept({path: '/to'}).reply(200, 'ok', { + headers: {'Content-Type': 'text/html'} + }) + + const document = `[a](https://example.com/from)` + const file = await remark().use(remarkLintNoDeadUrls).process(document) + + await mockAgent.close() + await setGlobalDispatcher(globalDispatcher) + + file.messages.sort(compareMessage) + + assert.deepEqual(file.messages.map(String), []) + }) })