Skip to content

Commit bccff54

Browse files
committed
some protections
1 parent 3b9c785 commit bccff54

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/core-js/modules/es.regexp.constructor.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ if (isForced('RegExp', BASE_FORCED)) {
127127
}
128128

129129
pattern = pattern === undefined ? '' : String(pattern);
130-
if (pattern === '') pattern = '(?:)';
130+
flags = flags === undefined ? '' : String(flags);
131131
rawPattern = pattern;
132132

133-
if (UNSUPPORTED_DOT_ALL) {
133+
if (UNSUPPORTED_DOT_ALL && 'dotAll' in re1) {
134134
dotAll = !!flags && flags.indexOf('s') > -1;
135135
if (dotAll) flags = flags.replace(/s/g, '');
136136
}
137137

138138
rawFlags = flags;
139139

140-
if (UNSUPPORTED_Y) {
140+
if (UNSUPPORTED_Y && 'sticky' in re1) {
141141
sticky = !!flags && flags.indexOf('y') > -1;
142142
if (sticky) flags = flags.replace(/y/g, '');
143143
}
@@ -166,7 +166,7 @@ if (isForced('RegExp', BASE_FORCED)) {
166166

167167
if (pattern !== rawPattern) try {
168168
// fails in old engines, but we have no alternatives for unsupported regex syntax
169-
createNonEnumerableProperty(result, 'source', rawPattern);
169+
createNonEnumerableProperty(result, 'source', rawPattern === '' ? '(?:)' : rawPattern);
170170
} catch (error) { /* empty */ }
171171

172172
return result;

0 commit comments

Comments
 (0)