Skip to content

Commit 7be6267

Browse files
committed
wrap tab URL construction in try-catch to handle malformed hrefs
1 parent cddfb5d commit 7be6267

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/support/steps/broken-links.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,20 @@ Then('WP Rocket settings links are not broken', async function (this: ICustomWor
3333

3434
// Get all tab URLs and visit each to collect their links
3535
const tabHrefs = await collectHrefsFromSelector(this.page, linkValidationSelectors.tabLinksInContent);
36-
const tabUrls = Array.from(new Set(tabHrefs)).map((href) => new URL(href, basePageUrl).toString());
36+
37+
const uniqueTabHrefs = Array.from(new Set(tabHrefs));
38+
const tabUrls: string[] = [];
39+
40+
for (const href of uniqueTabHrefs) {
41+
try {
42+
const url = new URL(href, basePageUrl);
43+
tabUrls.push(url.toString());
44+
} catch (error: unknown) {
45+
// Skip malformed tab URLs - they can't be navigated to anyway
46+
// eslint-disable-next-line no-console
47+
console.warn(`Skipping malformed tab href: ${href}`, error);
48+
}
49+
}
3750

3851
for (const tabUrl of tabUrls) {
3952
await this.page.goto(tabUrl);

0 commit comments

Comments
 (0)