Skip to content

Commit

Permalink
Fix that we would have tried to capture an asset with a malformed url…
Browse files Browse the repository at this point in the history
… with { origins: true }
  • Loading branch information
eoghanmurray committed Jul 10, 2024
1 parent b5661c6 commit 76400d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,17 @@ export function shouldIgnoreAsset(
for (const origin of originsToIgnore) {
if (url.startsWith(origin)) return true;
}

let urlOrigin;
try {
urlOrigin = new URL(url).origin;
} catch (e) {
return true; // something went wrong, ignore!
}
// Check the origins
const captureOrigins = config.origins;
if (typeof captureOrigins === 'boolean') {
return !captureOrigins;
} else if (Array.isArray(captureOrigins)) {
let urlOrigin;
try {
urlOrigin = new URL(url).origin;
} catch (e) {
return true; // something went wrong, ignore!
}
return !captureOrigins.includes(urlOrigin);
}
return true; // no config, ignore!
Expand Down
3 changes: 3 additions & 0 deletions packages/rrweb-snapshot/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ describe('utils', () => {
shouldIgnoreAsset('http:', { origins: ['http://example.com'] }),
).toBe(true);
});

it(`should ignore malformed url even with origins: true`, () => {
expect(shouldIgnoreAsset('http:', { origins: true })).toBe(true);
});
});

Expand Down

0 comments on commit 76400d6

Please sign in to comment.