@sebgroup/green-core 3.21.2 → 3.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,19 @@
1
1
  import "../../chunks/chunk.CAV4X6PU.js";
2
+ import { Script, createContext } from "node:vm";
2
3
  import { SEARCH_CONFIG, SEARCH_TIERS } from "./constants.js";
3
4
  import { RegexError } from "./errors.js";
5
+ const REGEX_TEST_TIMEOUT_MS = 250;
6
+ const regexTestScript = new Script("__result = __regex.test(__input)");
7
+ function safeRegexTest(regex, input) {
8
+ const sandbox = { __regex: regex, __input: input, __result: false };
9
+ try {
10
+ createContext(sandbox);
11
+ regexTestScript.runInContext(sandbox, { timeout: REGEX_TEST_TIMEOUT_MS });
12
+ return sandbox.__result;
13
+ } catch {
14
+ return false;
15
+ }
16
+ }
4
17
  function compileRegexPattern(pattern) {
5
18
  if (pattern.length > SEARCH_CONFIG.MAX_REGEX_LENGTH) {
6
19
  throw new RegexError(
@@ -29,12 +42,12 @@ function checkRegexMatch(item, regex, originalQuery) {
29
42
  const name = item.name.toLowerCase();
30
43
  const className = item.className.toLowerCase();
31
44
  const description = item.description?.toLowerCase() || "";
32
- const matches = regex.test(tagName) || regex.test(name) || regex.test(className) || regex.test(description);
45
+ const matches = safeRegexTest(regex, tagName) || safeRegexTest(regex, name) || safeRegexTest(regex, className) || safeRegexTest(regex, description);
33
46
  if (!matches) {
34
47
  return { matches: false, tier: 0, matchedTerms: 0 };
35
48
  }
36
49
  const lowerQuery = originalQuery.toLowerCase();
37
- if (regex.test(tagName)) {
50
+ if (safeRegexTest(regex, tagName)) {
38
51
  if (tagName === lowerQuery) {
39
52
  return { matches: true, tier: SEARCH_TIERS.EXACT_MATCH, matchedTerms: 1 };
40
53
  }