Skip to content

Commit

Permalink
some protections
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jun 20, 2021
1 parent 3b9c785 commit bccff54
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/core-js/modules/es.regexp.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ if (isForced('RegExp', BASE_FORCED)) {
}

pattern = pattern === undefined ? '' : String(pattern);
if (pattern === '') pattern = '(?:)';
flags = flags === undefined ? '' : String(flags);
rawPattern = pattern;

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

rawFlags = flags;

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

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

return result;
Expand Down

0 comments on commit bccff54

Please sign in to comment.