Skip to content

Commit c80904b

Browse files
motiz88facebook-github-bot
authored andcommitted
Protect against unsafe merging of regex patterns with inconsistent flags
Summary: Changelog: **[Fix]**: Protect against unsafe merging of `blockList` patterns with inconsistent regex flags. Reviewed By: GijsWeterings Differential Revision: D47060186 fbshipit-source-id: 63c9fe6f8ef0c20d14d12beb923b6443657b8d4e
1 parent 7a69b41 commit c80904b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/metro/src/node-haste/DependencyGraph/createHasteMap.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,24 @@ function getIgnorePattern(config: ConfigT): RegExp {
2626
}
2727

2828
const combine = (regexes: Array<RegExp>) =>
29-
new RegExp(regexes.map(regex => '(' + regex.source + ')').join('|'));
29+
new RegExp(
30+
regexes
31+
.map((regex, index) => {
32+
if (regex.flags !== regexes[0].flags) {
33+
throw new Error(
34+
'Cannot combine blockList patterns, because they have different flags:\n' +
35+
' - Pattern 0: ' +
36+
regexes[0].toString() +
37+
'\n' +
38+
` - Pattern ${index}: ` +
39+
regexes[index].toString(),
40+
);
41+
}
42+
return '(' + regex.source + ')';
43+
})
44+
.join('|'),
45+
regexes[0]?.flags ?? '',
46+
);
3047

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

0 commit comments

Comments
 (0)