Skip to content

Commit

Permalink
Protect against unsafe merging of regex patterns with inconsistent flags
Browse files Browse the repository at this point in the history
Summary: Changelog: **[Fix]**: Protect against unsafe merging of `blockList` patterns with inconsistent regex flags.

Reviewed By: GijsWeterings

Differential Revision: D47060186

fbshipit-source-id: 63c9fe6f8ef0c20d14d12beb923b6443657b8d4e
  • Loading branch information
motiz88 authored and facebook-github-bot committed Jun 28, 2023
1 parent 7a69b41 commit c80904b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/metro/src/node-haste/DependencyGraph/createHasteMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@ function getIgnorePattern(config: ConfigT): RegExp {
}

const combine = (regexes: Array<RegExp>) =>
new RegExp(regexes.map(regex => '(' + regex.source + ')').join('|'));
new RegExp(
regexes
.map((regex, index) => {
if (regex.flags !== regexes[0].flags) {
throw new Error(
'Cannot combine blockList patterns, because they have different flags:\n' +
' - Pattern 0: ' +
regexes[0].toString() +
'\n' +
` - Pattern ${index}: ` +
regexes[index].toString(),
);
}
return '(' + regex.source + ')';
})
.join('|'),
regexes[0]?.flags ?? '',
);

// If ignorePattern is an array, merge it into one
if (Array.isArray(ignorePattern)) {
Expand Down

0 comments on commit c80904b

Please sign in to comment.