diff --git a/rules/file-no-broken-links.js b/rules/file-no-broken-links.js index 6c30aba9..b4a42bd4 100644 --- a/rules/file-no-broken-links.js +++ b/rules/file-no-broken-links.js @@ -108,7 +108,10 @@ async function fileNoBrokenLinks(fs, options) { const filePath = path.posix.join('/', url.host, url.pathname) const absPath = path.posix.resolve(targetDir, filePath) const relPath = path.posix.relative(targetDir, absPath) - if (relPath.startsWith('..')) return null + if (relPath.startsWith('..')) { + if (options['pass-external-relative-links']) return null + else return `${originalURL} (relative link outside project)` + } // verify the file exists (or at least that we have access to it) if (!(await fs.relativeFileExists(relPath))) return `${originalURL} (file does not exist)` diff --git a/tests/rules/file_no_broken_links_tests.js b/tests/rules/file_no_broken_links_tests.js index 554b9ac8..59e82d83 100644 --- a/tests/rules/file_no_broken_links_tests.js +++ b/tests/rules/file_no_broken_links_tests.js @@ -199,13 +199,29 @@ describe('rule', () => { }) }) - it('returns true with a relative link to a file in markdown outside the working directory', async () => { + it('returns false with a relative link to a file in markdown outside the working directory', async () => { const ruleopts = { globsAll: ['relative_link_outside_dir.md'] } const actual = await fileNoBrokenLinks(testFs, ruleopts) + expect(actual.passed).to.equal(false) + expect(actual.targets).to.have.length(1) + expect(actual.targets[0]).to.deep.include({ + passed: false, + path: 'relative_link_outside_dir.md' + }) + }) + + it('returns true with a relative link to a file in markdown outside the working directory and pass-external-relative-links', async () => { + const ruleopts = { + globsAll: ['relative_link_outside_dir.md'], + 'pass-external-relative-links': true + } + + const actual = await fileNoBrokenLinks(testFs, ruleopts) + expect(actual.passed).to.equal(true) expect(actual.targets).to.have.length(1) expect(actual.targets[0]).to.deep.include({