Skip to content

Commit

Permalink
fix: environment options parsing error
Browse files Browse the repository at this point in the history
Previously vitest failed to parse environment options when they were
provided as a single line doc block like so:

    /** @vitest-environment-options {"url": "https://vitejs.dev"} */

The regular expression erroneously captured the JSON as well as " */".
  • Loading branch information
hahanein committed Jul 14, 2024
1 parent f851982 commit 0902212
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/utils/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function groupFilesByEnv(
)

const envOptions = JSON.parse(
code.match(/@(?:vitest|jest)-environment-options\s+?(.+)/)?.[1]
code.match(/@(?:vitest|jest)-environment-options\s+?(.+?)(?=\s*\*\/)/)?.[1]

Check failure on line 61 in packages/vitest/src/utils/test-helpers.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '\s+?' can exchange characters with '.+?'. Using any string accepted by /[\t\x0b\f \xa0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+/, this can be exploited to cause at least polynomial backtracking

Check failure on line 61 in packages/vitest/src/utils/test-helpers.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '\s+?' can exchange characters with '\s*'. Using any string accepted by /[\t\x0b\f \xa0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+/, this can be exploited to cause at least polynomial backtracking

Check failure on line 61 in packages/vitest/src/utils/test-helpers.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '.+?' can exchange characters with '\s*'. Using any string accepted by /[\t\x0b\f \xa0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+/, this can be exploited to cause at least polynomial backtracking
|| 'null',
)
const envKey = env === 'happy-dom' ? 'happyDOM' : env
Expand Down

0 comments on commit 0902212

Please sign in to comment.