Skip to content

Commit bfaa8dc

Browse files
committed
Do not follow cross-origin non-anchor relations in internalOnly mode
Fixes #198, #181
1 parent 63cdd47 commit bfaa8dc

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,8 @@ async function hyperlink(
687687
}
688688
} else if (relation.type === 'JavaScriptFetch') {
689689
follow = false;
690+
} else if (internalOnly) {
691+
follow = !relation.crossorigin;
690692
} else {
691693
follow = true;
692694
}

test/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,6 +2477,54 @@ describe('hyperlink', function () {
24772477
expect(t.close(), 'to satisfy', { fail: 0 });
24782478
});
24792479

2480+
// Regression test for https://github.com/Munter/hyperlink/issues/198
2481+
it('should not follow image/non-anchor relations to external assets', async function () {
2482+
httpception();
2483+
const t = new TapRender();
2484+
sinon.spy(t, 'push');
2485+
await hyperlink(
2486+
{
2487+
recursive: false,
2488+
internalOnly: true,
2489+
root: pathModule.resolve(__dirname, '..', 'testdata', 'issue198'),
2490+
inputUrls: ['index.html'],
2491+
},
2492+
t
2493+
);
2494+
2495+
expect(t.close(), 'to satisfy', {
2496+
count: 1,
2497+
pass: 1,
2498+
fail: 0,
2499+
skip: 0,
2500+
todo: 0,
2501+
});
2502+
});
2503+
2504+
// Regression test for https://github.com/Munter/hyperlink/issues/181
2505+
it('should not an <embed src=...> relation pointing at an external asset', async function () {
2506+
httpception();
2507+
const t = new TapRender();
2508+
sinon.spy(t, 'push');
2509+
await hyperlink(
2510+
{
2511+
recursive: false,
2512+
internalOnly: true,
2513+
root: pathModule.resolve(__dirname, '..', 'testdata', 'issue181'),
2514+
inputUrls: ['index.html'],
2515+
},
2516+
t
2517+
);
2518+
2519+
expect(t.close(), 'to satisfy', {
2520+
count: 1,
2521+
pass: 1,
2522+
fail: 0,
2523+
skip: 0,
2524+
todo: 0,
2525+
});
2526+
});
2527+
24802528
it('should follow fragment links within the same page', async () => {
24812529
const t = new TapRender();
24822530
// t.pipe(process.stdout);

testdata/issue181/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<embed src='http://www.thedailyshow.com/sitewide/video_player/view/default/swf.jhtml'></embed>

testdata/issue198/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="https://github.com/danielfdickinson/image-handling-mod-hugo-dfd/actions/workflows/build-and-verify.yml/badge.svg" alt="build-and-verify">

0 commit comments

Comments
 (0)