Skip to content

Commit

Permalink
fix: refactor extractUrls to split the text line by line first (#2122)
Browse files Browse the repository at this point in the history
This should protect us from OOM errors when processing a very large URL
list.
  • Loading branch information
B4nan committed Oct 10, 2023
1 parent 84cea6d commit 7265cd7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/utils/src/internals/extract-urls.ts
Expand Up @@ -73,6 +73,13 @@ export function extractUrls(options: ExtractUrlsOptions): string[] {
string: ow.string,
urlRegExp: ow.optional.regExp,
}));
const { string, urlRegExp = URL_NO_COMMAS_REGEX } = options;
return string.match(urlRegExp) || [];
const lines = options.string.split('\n');
const result: string[] = [];
const urlRegExp = options.urlRegExp ?? URL_NO_COMMAS_REGEX;

for (const line of lines) {
result.push(...(line.match(urlRegExp) ?? []));
}

return result;
}

0 comments on commit 7265cd7

Please sign in to comment.