MCPcopy Index your code
hub / github.com/parse-community/parse-server / safeRegexTest

Function safeRegexTest

src/LiveQuery/QueryTools.js:23–48  ·  view source on GitHub ↗
(pattern, flags, input)

Source from the content-addressed store, hash-verified

21
22// IMPORTANT: This function must remain synchronous. See vmContext comment above.
23function safeRegexTest(pattern, flags, input) {
24 try {
25 if (!regexTimeout) {
26 var re = new RegExp(pattern, flags);
27 return re.test(input);
28 }
29 var cacheKey = flags + ':' + pattern;
30 var script = scriptCache.get(cacheKey);
31 if (!script) {
32 if (scriptCache.size >= SCRIPT_CACHE_MAX) { scriptCache.clear(); }
33 script = new vm.Script('new RegExp(pattern, flags).test(input)');
34 scriptCache.set(cacheKey, script);
35 }
36 vmContext.pattern = pattern;
37 vmContext.flags = flags;
38 vmContext.input = input;
39 return script.runInContext(vmContext, { timeout: regexTimeout });
40 } catch (e) {
41 if (e.code === 'ERR_SCRIPT_EXECUTION_TIMEOUT') {
42 logger.warn(`Regex timeout: pattern "${pattern}" with flags "${flags}" exceeded ${regexTimeout}ms limit`);
43 } else {
44 logger.warn(`Invalid regex: pattern "${pattern}" with flags "${flags}": ${e.message}`);
45 }
46 return false;
47 }
48}
49
50/**
51 * Query Hashes are deterministic hashes for Parse Queries.

Callers 1

matchesKeyConstraintsFunction · 0.85

Calls 3

warnMethod · 0.80
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected