Skip to content

Commit 84319b3

Browse files
authored
fix(enqueueLinks): filter out empty/nullish globs (#2286)
Was noticed as an issue when running through apify where we'd get an empty element that throws a very non descriptive error Reported here: https://console.apify.com/actors/aYG0l9s7dbB7j3gbS/issues/Wd0Ahfk9Vd2OPk4Uf
1 parent 3d2c149 commit 84319b3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/core/src/enqueue_links/shared.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,22 @@ export function constructRegExpObjectsFromPseudoUrls(pseudoUrls: PseudoUrlInput[
7878
*/
7979
export function constructGlobObjectsFromGlobs(globs: GlobInput[]): GlobObject[] {
8080
return globs
81-
.filter((glob) => ((glob as GlobObject).glob || (glob as string)).trim().length > 0)
81+
.filter((glob) => {
82+
// Skip possibly nullish, empty strings
83+
if (!glob) {
84+
return false;
85+
}
86+
87+
if (typeof glob === 'string') {
88+
return glob.trim().length > 0;
89+
}
90+
91+
if (glob.glob) {
92+
return glob.glob.trim().length > 0;
93+
}
94+
95+
return false;
96+
})
8297
.map((item) => {
8398
// Get glob object from cache.
8499
let globObject = enqueueLinksPatternCache.get(item);

test/core/enqueue_links/enqueue_links.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ describe('enqueueLinks()', () => {
157157
'https://example.com/**/*',
158158
'',
159159
{ glob: ' ' },
160+
// Empty string used to throw an error (https://console.apify.com/actors/aYG0l9s7dbB7j3gbS/issues/Wd0Ahfk9Vd2OPk4Uf)
161+
{ glob: '' },
160162
{ glob: '?(http|https)://cool.com/', method: 'POST' as const },
161163
];
162164

0 commit comments

Comments
 (0)