diff --git a/src/mdast-process-images.js b/src/mdast-process-images.js index 9ed5ead..a97e738 100644 --- a/src/mdast-process-images.js +++ b/src/mdast-process-images.js @@ -39,7 +39,7 @@ export async function processImages(log, tree, mediaHandler, baseUrl) { visit(tree, (node) => { if (node.type === 'image') { const { url = '' } = node; - if (url.indexOf(':') < 0) { + if (url.indexOf(':') < 0 || url.startsWith('/')) { // eslint-disable-next-line no-param-reassign node.url = new URL(url, baseUrl).href; register(node); diff --git a/test/fixtures/images.html b/test/fixtures/images.html index 798c937..b721bfb 100644 --- a/test/fixtures/images.html +++ b/test/fixtures/images.html @@ -32,6 +32,9 @@

Hello, World.

+ + + diff --git a/test/fixtures/images.md b/test/fixtures/images.md index f981edf..d1d198e 100644 --- a/test/fixtures/images.md +++ b/test/fixtures/images.md @@ -16,6 +16,8 @@ ![][image1] +![][image0] + +-----------------------------------------+ | Metadata | +-----------+-----------------------------+ diff --git a/test/index.test.js b/test/index.test.js index 8ab80f5..445258a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -105,6 +105,10 @@ describe('Index Tests', () => { 'content-type': 'image/png', }) .get('/blog/relative.png') + .replyWithFile(200, testImagePath, { + 'content-type': 'image/png', + }) + .get('/adobe/assets/urn:aaid:aem:abcd') .replyWithFile(200, testImagePath, { 'content-type': 'image/png', }); @@ -115,10 +119,10 @@ describe('Index Tests', () => { }); nock('https://helix-media-bus.s3.us-east-1.amazonaws.com') .head('/foo-id/1c2e2c6c049ccf4b583431e14919687f3a39cc227') - .times(4) + .times(5) .reply(404) .put('/foo-id/1c2e2c6c049ccf4b583431e14919687f3a39cc227?x-id=PutObject') - .times(4) + .times(5) .reply(201); const expected = await readFile(resolve(__testdir, 'fixtures', 'images.md'), 'utf-8'); @@ -127,7 +131,7 @@ describe('Index Tests', () => { assert.strictEqual((await result.text()).trim(), expected.trim()); assert.deepStrictEqual(result.headers.plain(), { 'cache-control': 'no-store, private, must-revalidate', - 'content-length': '824', + 'content-length': '837', 'content-type': 'text/markdown; charset=utf-8', 'last-modified': 'Sat, 22 Feb 2031 15:28:00 GMT', 'x-source-location': 'https://www.example.com/blog/article', @@ -166,6 +170,11 @@ describe('Index Tests', () => { 'content-type': 'image/png', }) .get('/blog/relative.png') + .replyWithFile(200, testImagePath, { + 'content-type': 'image/png', + }) + .get('/adobe/assets/urn:aaid:aem:abcd') + .basicAuth({ user: 'john', pass: 'doe' }) .replyWithFile(200, testImagePath, { 'content-type': 'image/png', }); @@ -176,10 +185,10 @@ describe('Index Tests', () => { }); nock('https://helix-media-bus.s3.us-east-1.amazonaws.com') .head('/foo-id/1c2e2c6c049ccf4b583431e14919687f3a39cc227') - .times(4) + .times(5) .reply(404) .put('/foo-id/1c2e2c6c049ccf4b583431e14919687f3a39cc227?x-id=PutObject') - .times(4) + .times(5) .reply(201); const expected = await readFile(resolve(__testdir, 'fixtures', 'images.md'), 'utf-8'); @@ -188,7 +197,7 @@ describe('Index Tests', () => { assert.strictEqual((await result.text()).trim(), expected.trim()); assert.deepStrictEqual(result.headers.plain(), { 'cache-control': 'no-store, private, must-revalidate', - 'content-length': '824', + 'content-length': '837', 'content-type': 'text/markdown; charset=utf-8', 'last-modified': 'Sat, 22 Feb 2031 15:28:00 GMT', 'x-source-location': 'https://www.example.com/blog/article',