fix(android): use isRegExp for a more robust check in different execution contexts (#11359)

This commit is contained in:
William Bergeron-Drouin 2022-01-12 14:04:18 -05:00 committed by GitHub
parent 5751a1255b
commit a70f4e6410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@
*/
import fs from 'fs';
import { isString } from '../utils/utils';
import { isString, isRegExp } from '../utils/utils';
import * as channels from '../protocol/channels';
import { Events } from './events';
import { BrowserContext, prepareBrowserContextParams } from './browserContext';
@ -289,7 +289,7 @@ function toSelectorChannel(selector: api.AndroidSelector): channels.AndroidSelec
const toRegex = (value: RegExp | string | undefined): string | undefined => {
if (value === undefined)
return undefined;
if (value instanceof RegExp)
if (isRegExp(value))
return value.source;
return '^' + value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') + '$';
};