Skip to content

Commit

Permalink
Fix bug where fragment checks would be executed to links to external …
Browse files Browse the repository at this point in the history
…pages that were never loaded when runnin in internal mode
  • Loading branch information
Munter committed Aug 15, 2019
1 parent 3189efe commit 5593490
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ async function hyperlink(

for (const asset of ag.findAssets({
type: 'Html',
incomingFragments: { $exists: true }
incomingFragments: { $exists: true },
ids: { $exists: true }
})) {
for (const {
fragment,
Expand All @@ -701,7 +702,7 @@ async function hyperlink(
};

if (!shouldSkip(fragmentReport)) {
if (asset.ids && asset.ids.has(fragment.substr(1))) {
if (asset.ids.has(fragment.substr(1))) {
reportTest({
...fragmentReport,
ok: true,
Expand All @@ -711,7 +712,6 @@ async function hyperlink(
// Github does some weird things with mangling fragments and reversing it with runtime js
if (
asset.origin === 'https://github.com' &&
asset.ids &&
asset.ids.has(`user-content-${fragment.substr(1)}`)
) {
reportTest({
Expand Down
36 changes: 36 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,42 @@ describe('hyperlink', function() {
]);
expect(t.close(), 'to satisfy', { fail: 1 });
});

it('should not follow fragment links to external pages', async () => {
httpception([
{
request: 'GET https://test.com',
response: {
headers: {
'content-type': 'text/html'
},
body:
'<a href="https://nodejs.org/api/events.html#events_class_eventemitter"></a>'
}
}
]);

const t = new TapRender();
// t.pipe(process.stderr);
sinon.spy(t, 'push');
await hyperlink(
{
root: 'https://test.com',
inputUrls: ['https://test.com'],
internalOnly: true
},
t
);

expect(spyTapCalls(t.push), 'to satisfy', [
{
operator: 'load',
name: 'load https://test.com',
ok: true
}
]);
expect(t.close(), 'to satisfy', { pass: 1, fail: 0 });
});
});

describe('with Html responses in non-navigation relations', function() {
Expand Down

0 comments on commit 5593490

Please sign in to comment.